void Widget::SetParent( Widget::Ptr parent ) { auto cont = std::dynamic_pointer_cast<Container>( parent ); auto oldparent = m_parent.lock(); if( cont == oldparent ) { return; } if( oldparent ) { oldparent->Remove( shared_from_this() ); } m_parent = cont; auto iter = std::find( root_widgets.begin(), root_widgets.end(), this ); if( parent ) { // If this widget has a parent, it is no longer a root widget. if( iter != root_widgets.end() ) { root_widgets.erase( iter ); } SetHierarchyLevel( parent->GetHierarchyLevel() + 1 ); } else { // If this widget does not have a parent, it becomes a root widget. if( iter == root_widgets.end() ) { root_widgets.push_back( this ); } SetHierarchyLevel( 0 ); } HandleAbsolutePositionChange(); }
void Widget::AllocateSize( const sf::FloatRect& rect ) const { sf::FloatRect oldallocation( m_allocation ); // Make sure allocation is pixel-aligned. m_allocation.Left = std::floor( rect.Left + .5f ); m_allocation.Top = std::floor( rect.Top + .5f ); m_allocation.Width = std::floor( rect.Width + .5f ); m_allocation.Height = std::floor( rect.Height + .5f ); if( oldallocation.Top == m_allocation.Top && oldallocation.Left == m_allocation.Left && oldallocation.Width == m_allocation.Width && oldallocation.Height == m_allocation.Height ) { // Nothing even changed. Save the hierarchy the trouble. return; } HandleAbsolutePositionChange(); HandleSizeAllocate( oldallocation ); OnSizeAllocate(); Invalidate(); }
void Widget::SetAllocation( const sf::FloatRect& rect ) { sf::FloatRect oldallocation( m_allocation ); // Make sure allocation is pixel-aligned. m_allocation.left = std::floor( rect.left + .5f ); m_allocation.top = std::floor( rect.top + .5f ); m_allocation.width = std::floor( rect.width + .5f ); m_allocation.height = std::floor( rect.height + .5f ); if( oldallocation.top == m_allocation.top && oldallocation.left == m_allocation.left && oldallocation.width == m_allocation.width && oldallocation.height == m_allocation.height ) { // Nothing even changed. Save the hierarchy the trouble. return; } if( ( oldallocation.top != m_allocation.top ) || ( oldallocation.left != m_allocation.left ) ) { HandlePositionChange(); HandleAbsolutePositionChange(); } if( ( oldallocation.width != m_allocation.width ) || ( oldallocation.height != m_allocation.height ) ) { HandleSizeChange(); Invalidate(); GetSignals().Emit( OnSizeAllocate ); } }
void Widget::SetPosition( const sf::Vector2f& position ) { sf::FloatRect allocation( GetAllocation() ); // Make sure allocation is pixel-aligned. m_allocation.left = std::floor( position.x + .5f ); m_allocation.top = std::floor( position.y + .5f ); if( ( allocation.top != m_allocation.top ) || ( allocation.left != m_allocation.left ) ) { HandlePositionChange(); HandleAbsolutePositionChange(); } }
void Widget::Refresh() const { sf::FloatRect old_allocation( GetAllocation() ); RequestSize(); if( old_allocation.Left == GetAllocation().Left && old_allocation.Top == GetAllocation().Top && old_allocation.Width == GetAllocation().Width && old_allocation.Height == GetAllocation().Height ) { HandleAbsolutePositionChange(); HandleSizeAllocate( old_allocation ); } Invalidate(); }
void Widget::SetParent( const Widget::Ptr& parent ) { Container::Ptr cont( DynamicPointerCast<Container>( parent ) ); if( !cont ) { return; } Container::Ptr oldparent = m_parent.lock(); if( oldparent ) { oldparent->Remove( shared_from_this() ); } m_parent = cont; SetHierarchyLevel( parent->GetHierarchyLevel() + 1 ); HandleAbsolutePositionChange(); }
void Widget::SetPosition( const sf::Vector2f& position ) const { sf::FloatRect oldallocation( GetAllocation() ); // Make sure allocation is pixel-aligned. m_allocation.Left = std::floor( position.x + .5f ); m_allocation.Top = std::floor( position.y + .5f ); if( oldallocation.Top == m_allocation.Top && oldallocation.Left == m_allocation.Left ) { // Nothing even changed. Save the hierarchy the trouble. return; } HandleAbsolutePositionChange(); HandleSizeAllocate( oldallocation ); if( m_drawable ) { m_drawable->SetPosition( GetAbsolutePosition() ); } OnSizeAllocate(); }