MCPcopy Create free account
hub / github.com/TankOs/SFGUI / SetParent

Method SetParent

src/SFGUI/Widget.cpp:240–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240void Widget::SetParent( Widget::Ptr parent ) {
241 auto cont = std::dynamic_pointer_cast<Container>( parent );
242 auto oldparent = m_parent.lock();
243
244 if( cont == oldparent ) {
245 return;
246 }
247
248 if( oldparent ) {
249 oldparent->Remove( shared_from_this() );
250 }
251
252 m_parent = cont;
253
254 auto iter = std::find( root_widgets.begin(), root_widgets.end(), this );
255
256 if( parent ) {
257 // If this widget has a parent, it is no longer a root widget.
258 if( iter != root_widgets.end() ) {
259 root_widgets.erase( iter );
260 }
261
262 SetHierarchyLevel( parent->GetHierarchyLevel() + 1 );
263 }
264 else {
265 // If this widget does not have a parent, it becomes a root widget.
266 if( iter == root_widgets.end() ) {
267 root_widgets.push_back( this );
268 }
269
270 SetHierarchyLevel( 0 );
271 }
272
273 HandleAbsolutePositionChange();
274}
275
276void Widget::SetPosition( const sf::Vector2f& position ) {
277 sf::FloatRect allocation( GetAllocation() );

Callers 3

AddMethod · 0.80
RemoveMethod · 0.80
RemoveAllMethod · 0.80

Calls 3

endMethod · 0.80
GetHierarchyLevelMethod · 0.80
RemoveMethod · 0.45

Tested by

no test coverage detected