Skip to content

Element.HeightForWidth ignores child margins in the column branch #165

Closed

Description

@grindlemire

The column branch of Element.HeightForWidth (element_layout.go) measures every child at the full content width and sums the returned heights, ignoring the child's margins in both directions. The layout engine subtracts Margin.Horizontal() before measuring in recomputeTextWrapping and includes Margin.Vertical() in the main size, so a nested column reports a smaller height than layout gives its children.

Reproduction: a 29 character text ("aaaaa bbbbb ccccc ddddd eeeee") with WithMarginTRBL(0, 2, 0, 2) inside a column, which is itself a child of a column with WithWidth(20) followed by a text sibling. inner.HeightForWidth(20) returns 2, but the text is laid out 16 wide and wraps to 3 rows; the sibling is placed at Y=2 and overlaps the last line. The numbers are identical with WithAlign(AlignStart) on the inner column and with the default stretch. Putting the same text directly in the 20 wide column (no nesting) is correct: 16 wide, 3 rows, sibling at Y=3.

Likely fix: in that loop subtract child.style.Margin.Horizontal() from the available width before the stretch and clamp branches, and add child.style.Margin.Vertical() to totalH, then cover it with a nested-column case in element_layout_colwrap_test.go. Predates #162; noted during its review.

Activity

  1. added a commit that references this issue on Sep 16, 2026
    e4aa0ac
  2. added a commit that references this issue on Sep 18, 2026
    118a647
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions