Skip to content

[patch] Stretch StackPanel children across the cross axis so alignment applies - #195

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/158-stackpanel-cross-axis
Oct 6, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/158-stackpanel-cross-axis

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #158

What changed

StackPanel.OnArrangeChildren now gives each child the panel's full content width in a vertical stack, and its full content height in a horizontal stack. On the stacking axis each child keeps its measured size, so the stacking offsets do not change. A centered or right-aligned TextElement, or a BorderElement header in a vertical stack, now has room to align or span. Before, it was boxed to exactly its content width.

Behaviour change to review

Two existing tests checked the old content-sized cross axis, so I updated them:

  • StackPanelVerticalMeasuresWidthIndependentElementsAtTheirOwnSize now expects a width of 10 (the panel) rather than 3 for a fixed-size child. The measured height, and the next child's position, are still asserted unchanged.
  • RenderAfterAResizeRelaysOutEveryContainerBeneathTheRoot: the precondition now expects the label to span the panel rather than sit at its text width. The post-resize assertion, which checks that the label is re-laid out to the narrower width, is unchanged.

This PR adds no opt-out Stretch property (triage listed it as optional). Any element that wants a content-sized box inside a stack now has to position itself with its own alignment.

Tests

  • StackPanelVerticalChildAlignsWithinThePanelWidth covers Left/Center/Right. It is the issue's minimal repro: "hi" in a 40-wide vertical stack is drawn at x=0, 19 and 38.
  • StackPanelHorizontalChildSpansThePanelHeight checks that the cross-axis height is stretched and that widths and offsets on the stacking axis are kept.
  • With the fix reverted, the new tests and the two updated tests fail (6 failures). With it applied, the full suite passes (251/251) and the solution builds without warnings.

Independent of #194 (#157). Both branch from main.

🤖 Generated with Claude Code

https://claude.ai/code/session_015YFg3aG1od37a8RytUTWQy


Generated by Claude Code

…pplies [patch]

A StackPanel gave each child its measured size on both axes, so a child's
box was exactly as wide (vertical) or tall (horizontal) as its content and
HorizontalAlignment.Center/Right had no room to act. Children now span the
panel on the cross axis and keep their measured size on the stacking axis,
so stacking offsets are unchanged.

Fixes #158

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

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit c96f89b into main Oct 6, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/158-stackpanel-cross-axis branch October 6, 2026 06:54
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