Skip to content
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

The x-coordinate of the grandson node of the column wrapping node is incorrect. LAY_WRAP | LAY_COLUMN #20

Open
haoyu234 opened this issue Oct 25, 2024 · 0 comments · May be fixed by #21

Comments

@haoyu234
Copy link

haoyu234 commented Oct 25, 2024

node1 is root node. with LAY_WRAP | LAY_COLUMN flags. margin 5, 5, 5, 5
node2 is a child of node1. margin 5, 5, 5, 5
node3 is a child of node2. margin 5, 5, 5, 5

image

Expected results:
image

test case:

// Incorrect results:
// root, 50, 50, 60, 200
// node2, 55, 125, 50, 50
// node3, 5, 125, 50, 50

// Expected result:
// node3, 60, 130, 50, 50

lay_id root = lay_item(ctx);
lay_set_size_xy(ctx, root, 200, 200);
lay_set_margins_ltrb(ctx, root, 50, 50, 50, 50);
lay_set_contain(ctx, root, LAY_WRAP | LAY_COLUMN);

lay_id node2 = lay_item(ctx);
lay_set_size_xy(ctx, node2, 50, 50);
lay_set_margins_ltrb(ctx, node2, 5, 5, 5, 5);
lay_insert(ctx, root, node2);

lay_id node3 = lay_item(ctx);
lay_set_size_xy(ctx, node3, 50, 50);
lay_set_margins_ltrb(ctx, node3, 5, 5, 5, 5);
lay_insert(ctx, node2, node3);

lay_run_context(ctx);

Here's my workground code that seems to fix this:

// in lay_arrange
    case LAY_COLUMN | LAY_WRAP:
        if (dim != 0) {
            lay_arrange_stacked(ctx, item, 1, true);

  // note: The x-coordinates are recalculated here, 
  // but the child nodes are not recursively updated, so just add the relevant code
            lay_scalar offset = lay_arrange_wrapped_overlay_squeezed(ctx, item, 0);
            ctx->rects[item][2 + 0] = offset - ctx->rects[item][0];

            // ----- workground begin
            lay_id child = pitem->first_child;
            while (child != LAY_INVALID_ID) {
                // NOTE: this is recursive and will run out of stack space if items are
                // nested too deeply.
                lay_arrange(ctx, child, 0);
                lay_item_t *pchild = lay_get_item(ctx, child);
                child = pchild->next_sibling;
            }

            break;
            // ----- workground end
        }
        // ----- workground begin
        return;
        // ----- workground end
        break;

image

The patch in issue #15 needs to be used (lay_arrange_overlay and lay_arrange_overlay_squeezed_range).

Exported layout files:
grandsonx.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant