Skip to content

Measure a container's children from its content origin - #176

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/145-container-measure
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/145-container-measure

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #145

What changed

UIContainerBase.OnCalculateRequiredDimensionsForChildren measured each child as child.Position + childDimensions. Child positions are absolute screen coordinates, so the container's own position and padding ended up in its required size. OnCalculateRequiredDimensions then added the padding a second time. The default measurement now works relative to GetContentPosition(), and padding is still added once.

StackPanel and BorderElement override this method, so they aren't affected. The fix is for custom containers that rely on the default.

Tests

New UIContainerBaseMeasureTests uses a minimal container that keeps the default measurement:

  • A container at (10,5) with Padding.Uniform(1) holding TextElement("abc") measures 5×3. Before the fix it measured 16×9.
  • The measured size is the same at the origin and at (40,12).

Both tests failed before the fix. The full suite passes with it (211/211).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCL6GX9wshgqiBeq6z98ZH


Generated by Claude Code

The default OnCalculateRequiredDimensionsForChildren measured each child's
extent from screen column/row 0, so a custom container's required size
included its own position and its padding, which OnCalculateRequiredDimensions
then added again. A 5x3 container at (10,5) measured 16x9. Children are now
measured relative to GetContentPosition().

Fixes #145

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit bb02a38 into main Sep 29, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/145-container-measure branch September 29, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UIContainerBase's default measurement adds the container's screen position and double-counts padding (a 5×3 container at (10,5) measures 16×9)

1 participant