6 using namespace awful::gui::game
;
8 VGroup::VGroup( Container
* pParent_
) :
9 SimpleContainer( pParent_
),
14 void VGroup::calcMinMax()
16 SimpleContainer::calcMinMax();
18 bool bUnlimited
= false;
19 math::Vector2f min
, max
;
22 WidgetList::const_iterator it
;
23 for( it
= m_Children
.begin(); it
!= m_Children
.end(); ++it
)
26 const math::Vector2f
& cmin
= ( *it
)->getMinSize();
27 const math::Vector2f
& cmax
= ( *it
)->getMaxSize();
34 if( cmin
.x() > min
.x() )
37 if( cmax
.x() > max
.x() )
45 if( max
.x() && max
.x() < min
.x() )
55 enum WidgetLayoutState
64 WidgetList::size_type numchildren
= m_Children
.size();
66 const math::Rectf
& r( getRect() );
67 float FreeSpace
= r
.height() - m_Spacing
* static_cast< float >( numchildren
- 1 );
69 // Currently, all children have a weight of 1. I'll implement weighted layout
70 // if I need it (aka if I feel like it).
71 float TotalWeight
= static_cast< float >( numchildren
);
73 std::vector
< WidgetLayoutState
> states( numchildren
);
74 bool bMoreSpace
= true;
75 WidgetList::const_iterator it
;
78 // Outer loop: loop until the inner loop manage to go through all the children
79 // without changing their layout state.
82 for( it
= m_Children
.begin(), i
= 0; it
!= m_Children
.end(); ++it
, ++i
)
84 const math::Vector2f
& min
= ( *it
)->getMinSize();
85 const math::Vector2f
& max
= ( *it
)->getMaxSize();
87 if( states
[i
] == s_Free
)
89 float size
= FreeSpace
/ TotalWeight
;
99 if( max
.y() && size
> max
.y() )
103 FreeSpace
-= max
.y();
110 if( bMoreSpace
&& states
[i
] == s_Min
)
113 FreeSpace
+= min
.y();
114 float size
= FreeSpace
/ TotalWeight
;
123 FreeSpace
-= min
.y();
127 if( !bMoreSpace
&& states
[i
] == s_Max
)
130 FreeSpace
+= max
.y();
131 float size
= FreeSpace
/ TotalWeight
;
140 FreeSpace
-= max
.y();
145 } while( it
!= m_Children
.end() );
149 for( it
= m_Children
.begin(), i
= 0; it
!= m_Children
.end(); ++it
, ++i
)
151 const math::Vector2f
& min
= ( *it
)->getMinSize();
152 const math::Vector2f
& max
= ( *it
)->getMaxSize();
154 crect
.width() = r
.width();
155 if( crect
.width() < min
.x() )
156 crect
.width() = min
.x();
157 if( max
.x() && crect
.width() > max
.x() )
158 crect
.height() = max
.x();
163 crect
.height() = FreeSpace
/ TotalWeight
;
167 crect
.height() = min
.y();
171 crect
.height() = max
.y();
175 ( *it
)->setRect( crect
);
176 crect
.top() += crect
.height() + m_Spacing
;
179 SimpleContainer::layout();