Skip to content

Layout measures wrapping height before MinWidth/MaxWidth are applied #164

Closed

Description

@grindlemire

computeBorderBox (internal/layout/calculate.go) applies a child's MinWidth and MaxWidth after the flex slot is assigned, but neither wrapping measurement site consults them: recomputeTextWrapping in internal/layout/flex.go (both the stretch and non-stretch column branches) and the column branch of Element.HeightForWidth in element_layout.go. The child is measured at the slot width and laid out at the constrained width, so the allocated height is wrong whenever the constraint changes wrapping.

Reproduction: a 29 character text ("aaaaa bbbbb ccccc ddddd eeeee") with WithMaxWidth(15) as a child of a column with WithWidth(20) and a text sibling below it. Result: the text is laid out 15 wide, which wraps to 3 rows, but it is allocated 2 rows and the sibling is placed at Y=2, overlapping the last line. WithMaxWidth(10) gives 5 rows needed and 2 allocated. The numbers are the same with WithAlign(AlignStart) on the column (non-stretch) and with the default stretch. A MinWidth above the slot has the opposite effect: the child is measured narrower than it is laid out and gets extra rows.

Likely fix: at both measurement sites, clamp the measured width with the child's MinWidth and MaxWidth resolved against that width, mirroring computeBorderBox, and add a case for each branch to element_layout_colwrap_test.go and calculate_colwrap_test.go. Predates #162; noted during its review.

Activity

  1. added a commit that references this issue on Sep 16, 2026
    8d806c0
  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