Skip to content

Commit b6f0578

Browse files
committed
Fix left margin unaccounted in lay_arrange_overlay
lay_arrange_overlay() did not account for the left (or top) child margin in the LAY_RIGHT fill case for a child. This could cause it to have an incorrect offset if the child actually had a margin and LAY_RIGHT (or bottom) was specified. This commit also includes two test cases that will fail before the patch, and succeed after the patch. The user who reported the issue says that there may remain an issue in lay_arrange_overlay_squeezed_range, but it has not yet been tested and this commit does not address any possible issue there.
1 parent e9bc8f2 commit b6f0578

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

layout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ void lay_arrange_overlay(lay_context *ctx, lay_id item, int dim)
10691069
child_rect[dim] += (space - child_rect[2 + dim]) / 2 - child_margins[wdim];
10701070
break;
10711071
case LAY_RIGHT:
1072-
child_rect[dim] += space - child_rect[2 + dim] - child_margins[wdim];
1072+
child_rect[dim] += space - child_rect[2 + dim] - child_margins[dim] - child_margins[wdim];
10731073
break;
10741074
case LAY_HFILL:
10751075
child_rect[2 + dim] = lay_scalar_max(0, space - child_rect[dim] - child_margins[wdim]);

test_layout.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,40 @@ LTEST_DECLARE(wrap_column_4)
886886
free(items);
887887
}
888888

889+
LTEST_DECLARE(anchor_right_margin1)
890+
{
891+
lay_id root = lay_item(ctx);
892+
lay_set_size_xy(ctx, root, 100, 100);
893+
894+
lay_id child = lay_item(ctx);
895+
lay_set_size_xy(ctx, child, 50, 50);
896+
lay_set_margins_ltrb(ctx, child, 5, 5, 0, 0);
897+
lay_set_behave(ctx, child, LAY_BOTTOM | LAY_RIGHT);
898+
899+
lay_insert(ctx, root, child);
900+
901+
lay_run_context(ctx);
902+
903+
LTEST_VEC4EQ(lay_get_rect(ctx, child), 50, 50, 50, 50);
904+
}
905+
906+
LTEST_DECLARE(anchor_right_margin2)
907+
{
908+
lay_id root = lay_item(ctx);
909+
lay_set_size_xy(ctx, root, 100, 100);
910+
911+
lay_id child = lay_item(ctx);
912+
lay_set_size_xy(ctx, child, 50, 50);
913+
lay_set_margins_ltrb(ctx, child, 5, 5, 10, 10);
914+
lay_set_behave(ctx, child, LAY_BOTTOM | LAY_RIGHT);
915+
916+
lay_insert(ctx, root, child);
917+
918+
lay_run_context(ctx);
919+
920+
LTEST_VEC4EQ(lay_get_rect(ctx, child), 40, 40, 50, 50);
921+
}
922+
889923
// Call in main to run a test by name
890924
//
891925
// Resets string buffer and lay context before running test
@@ -930,6 +964,8 @@ int main(int argc, char** argv)
930964
LTEST_RUN(wrap_column_2);
931965
LTEST_RUN(wrap_column_3);
932966
LTEST_RUN(wrap_column_4);
967+
LTEST_RUN(anchor_right_margin1);
968+
LTEST_RUN(anchor_right_margin2);
933969

934970
printf("Finished tests\n");
935971

0 commit comments

Comments
 (0)