| 174 | } |
| 175 | |
| 176 | void Box::AllocateChildren() const { |
| 177 | unsigned int num_expand( 0 ); |
| 178 | unsigned int num_visible( 0 ); |
| 179 | |
| 180 | // Count number of visible and expanded children. |
| 181 | for( const auto& child : m_box_children ) { |
| 182 | if( !IsChildInteresting( child.widget ) ) { |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | ++num_visible; |
| 187 | |
| 188 | if( child.expand ) { |
| 189 | ++num_expand; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Calculate extra width pre expanded widget. |
| 194 | float extra( 0.f ); |
| 195 | |
| 196 | if( num_expand > 0 ) { |
| 197 | if( m_orientation == Orientation::HORIZONTAL ) { |
| 198 | extra = std::max( 0.f, GetAllocation().size.x - GetRequisition().x ) / static_cast<float>( num_expand ); |
| 199 | } |
| 200 | else { |
| 201 | extra = std::max( 0.f, GetAllocation().size.y - GetRequisition().y ) / static_cast<float>( num_expand ); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Allocate children. |
| 206 | float gap( Context::Get().GetEngine().GetProperty<float>( "Gap", shared_from_this() ) ); |
| 207 | sf::Vector2f allocation( 0.f, 0.f ); |
| 208 | sf::Vector2f position( gap, gap ); |
| 209 | |
| 210 | for( const auto& child : m_box_children ) { |
| 211 | if( !IsChildInteresting( child.widget ) ) { |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | if( m_orientation == Orientation::HORIZONTAL ) { |
| 216 | allocation.x = child.widget->GetRequisition().x + ( child.expand ? extra : 0.f ); |
| 217 | allocation.y = GetAllocation().size.y - 2 * gap; |
| 218 | |
| 219 | child.widget->SetAllocation( sf::FloatRect( position, { allocation.x - ( child.expand && !child.fill ? extra : 0.f ), allocation.y }) ); |
| 220 | position.x += allocation.x + GetSpacing(); |
| 221 | } |
| 222 | else { |
| 223 | allocation.x = GetAllocation().size.x - 2 * gap; |
| 224 | allocation.y = child.widget->GetRequisition().y + ( child.expand ? extra : 0.f ); |
| 225 | |
| 226 | child.widget->SetAllocation( sf::FloatRect( position, { allocation.x, allocation.y - ( child.expand && !child.fill ? extra : 0.f ) }) ); |
| 227 | position.y += allocation.y + GetSpacing(); |
| 228 | } |
| 229 | |
| 230 | --num_visible; |
| 231 | } |
| 232 | } |
| 233 |
nothing calls this directly
no test coverage detected