Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/ui/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ void ui::LinearLayout::layout( View *view )
} );

// Update layout based on selected mode and primary axis.
size_t index = 0;
float offset = mMargin.getUpperLeft()[axis];
float negativeOffset = containerSize[axis] - mMargin.getLowerRight()[axis];
for( auto &subview : subviews ) {
if( mMode == Mode::DISTRIBUTE ) {
if( mMode == Mode::INCREMENT ) {
updateAxisPos( subview, offset, axis );
offset += subview->getSize()[axis] + mPadding;
}
else if( mMode == Mode::DISTRIBUTE ) {
offset += ( containerSizeMinusMargins - subviewsTotal ) / float( subviews.size() + 1 );
updateAxisPos( subview, offset, axis );
offset += subview->getSize()[axis];
Expand All @@ -76,10 +82,18 @@ void ui::LinearLayout::layout( View *view )
updateAxisPos( subview, offset, axis );
offset += subview->getSize()[axis] + mPadding;
}
else {
updateAxisPos( subview, offset, axis );
offset += subview->getSize()[axis] + mPadding;
else if( mMode == Mode::PERIPHERAL ) {
if( index < glm::ceil( 0.5f * subviews.size() ) ) {
updateAxisPos( subview, offset, axis );
offset += subview->getSize()[axis] + mPadding;
}
else {
negativeOffset -= subview->getSize()[axis];
updateAxisPos( subview, negativeOffset, axis );
negativeOffset -= mPadding;
}
}
++index;
}

// Update alignment of all subviews on secondary axis.
Expand Down
1 change: 1 addition & 0 deletions src/ui/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class LinearLayout : public Layout {
INCREMENT = 0, //! Each successive View is placed after the previous one + margin
FILL, //! Spreads and expands subviews, overriding each subview's size.
DISTRIBUTE, //! Spreads subviews equally based on their center. Ignores padding.
PERIPHERAL, //! Stacks subviews on each side.
NUM_MODES
};

Expand Down
6 changes: 3 additions & 3 deletions test/src/LayoutTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void LayoutTests::addLabels( const ui::ViewRef &view, size_t count )
void LayoutTests::layout()
{
mHorizontalGroupView->setPos( vec2( 40, 40 ) );
mHorizontalGroupView->setSize( vec2( 800, 80 ) );
mHorizontalGroupView->setSize( vec2( 800, 100 ) );

mVerticalGroupView->setPos( vec2( 40, 140 ) );
mVerticalGroupView->setSize( vec2( 300, 300 ) );
mVerticalGroupView->setPos( vec2( 40, 180 ) );
mVerticalGroupView->setSize( vec2( 300, 400 ) );
}

bool LayoutTests::keyDown( ci::app::KeyEvent &event )
Expand Down