Skip to content

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

Open
@haoyu234

Description

@haoyu234

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions