| 10 | } |
| 11 | |
| 12 | void VerticalLayout::update(float) { |
| 13 | m_size = Vec2I(0, 0); |
| 14 | |
| 15 | if (m_members.empty()) |
| 16 | return; |
| 17 | |
| 18 | for (auto const& child : m_members) { |
| 19 | auto childSize = child->size(); |
| 20 | m_size[1] += childSize[1]; |
| 21 | m_size[0] = max(m_size[0], childSize[0]); |
| 22 | } |
| 23 | m_size[1] += (m_members.size() - 1) * m_verticalSpacing; |
| 24 | |
| 25 | auto bounds = contentBoundRect(); |
| 26 | |
| 27 | int verticalPos = m_fillDown ? bounds.yMax() : bounds.yMin(); |
| 28 | for (auto const& child : reverseIterate(m_members)) { |
| 29 | auto childSize = child->size(); |
| 30 | |
| 31 | Vec2I targetPosition; |
| 32 | |
| 33 | if (m_horizontalAnchor == HorizontalAnchor::LeftAnchor) |
| 34 | targetPosition[0] = bounds.xMin(); |
| 35 | else if (m_horizontalAnchor == HorizontalAnchor::RightAnchor) |
| 36 | targetPosition[0] = bounds.xMax() - childSize[0]; |
| 37 | else if (m_horizontalAnchor == HorizontalAnchor::HMidAnchor) |
| 38 | targetPosition[0] = -childSize[0] / 2; |
| 39 | |
| 40 | if (m_fillDown) { |
| 41 | verticalPos -= childSize[1]; |
| 42 | targetPosition[1] = verticalPos; |
| 43 | verticalPos -= m_verticalSpacing; |
| 44 | } else { |
| 45 | targetPosition[1] = verticalPos; |
| 46 | verticalPos -= childSize[1]; |
| 47 | verticalPos -= m_verticalSpacing; |
| 48 | } |
| 49 | |
| 50 | // needed because position is included in relativeBoundRect |
| 51 | child->setPosition(Vec2I(0, 0)); |
| 52 | |
| 53 | child->setPosition(targetPosition - child->relativeBoundRect().min()); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | Vec2I VerticalLayout::size() const { |
| 58 | return m_size; |
nothing calls this directly
no test coverage detected