Skip to content

fix test case wrap_row_5, the last row was ignored #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 5 additions & 5 deletions layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ void lay_arrange_stacked(
uint32_t count = 0; // count of fillers
uint32_t squeezed_count = 0; // count of squeezable elements
uint32_t total = 0;
bool hardbreak = false;
uint32_t before_wrap_count = 0; // count of elements before wrap
// first pass: count items that need to be expanded,
// and the space that is used
lay_id child = start_child;
Expand All @@ -951,12 +951,13 @@ void lay_arrange_stacked(
++squeezed_count;
extend += child_rect[dim] + child_rect[2 + dim] + child_margins[wdim];
}
++ before_wrap_count;
// wrap on end of line or manual flag
if (wrap && (
total && ((extend > space) ||
(child_flags & LAY_BREAK)))) {
end_child = child;
hardbreak = (child_flags & LAY_BREAK) == LAY_BREAK;
before_wrap_count = 0;
// add marker for subsequent queries
pchild->flags = child_flags | LAY_BREAK;
break;
Expand All @@ -979,9 +980,8 @@ void lay_arrange_stacked(
else if (total > 0) {
switch (item_flags & LAY_JUSTIFY) {
case LAY_JUSTIFY:
// justify when not wrapping or not in last line,
// or not manually breaking
if (!wrap || ((end_child != LAY_INVALID_ID) && !hardbreak))
// justify when not wrapping or at least one remaining element
if (!wrap || end_child != LAY_INVALID_ID || before_wrap_count > 0)
spacer = (float)extra_space / (float)(total - 1);
break;
case LAY_START:
Expand Down
4 changes: 1 addition & 3 deletions test_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,7 @@ LTEST_DECLARE(wrap_row_5)

lay_run_context(ctx);

// TODO note we're adding the -5 here so we ignore the last row, which
// seems to be bugged
for (int16_t i = 0; i < num_items - 5; ++i) {
for (int16_t i = 0; i < num_items; ++i) {
int16_t x, y;
x = i % 5;
y = i / 5;
Expand Down