Skip to content

Measure a container with no room past its padding as the padding alone [patch] - #254

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/249-container-no-room-measures-padding
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/249-container-no-room-measures-padding

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #249

What changed

When a container got no more width than its padding (2 columns or fewer for a BorderElement), UIContainerBase.OnCalculateRequiredDimensions(int) measured its children at Math.Max(0, availableWidth - Padding.Horizontal), which is 0. TextElement reads 0 as "no constraint", so a word-wrapped child reported its full unwrapped height. In the issue's layout, the squeezed border drew a hollow 2×7 box, and "below" landed at y=7 instead of y=2. This is #198's symptom again, reached through a container rather than through TextElement itself.

For 0 < availableWidth <= Padding.Horizontal, the container now returns Dimensions.Empty.WithPadding(Padding) without measuring its children. This is the same branch TextElement got for #198. The unconstrained (0) and roomier cases measure exactly as before. The longer-term change the issue mentions, a nullable width instead of 0 meaning "unconstrained", is left out of this PR.

Tests

The tests are in a new file, ContainerNoRoomMeasureTests:

  • BorderWithNoRoomForItsChildMeasuresAsTheBareBorder(1|2): a bordered wrapped child measures 2×2
  • BorderWithOneColumnOfRoomStillMeasuresItsChild: width 3 still measures the child (3×4)
  • SqueezedBorderDoesNotPushTheNextRowDown: the issue's 19×20 layout puts "below" at y=2

With the UIContainerBase change reverted, the two no-room cases and the layout test fail. The full suite passes (331/331). The branch also merges cleanly with open PR #252, which edits nearby measurement code for #190.


Generated by Claude Code

…ing alone

UIContainerBase measured its children at width 0 when the container got
no more width than its padding, and TextElement reads 0 as "no
constraint". A BorderElement squeezed to 2 columns then reported its
child's full unwrapped height, drew a hollow box that tall and pushed
the siblings below it down. The container now returns the padding alone
in that case, as TextElement does since #198.

Fixes #249

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4towbdqS7BHdCDNqm
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants