| 238 | } |
| 239 | |
| 240 | void 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 | |
| 276 | void Widget::SetPosition( const sf::Vector2f& position ) { |
| 277 | sf::FloatRect allocation( GetAllocation() ); |