Skip to content

Fix Align measure to respect explicitly set width#2101

Merged
patriksvensson merged 2 commits intospectreconsole:mainfrom
GrantTotinov:fix-align-measure-width
Apr 25, 2026
Merged

Fix Align measure to respect explicitly set width#2101
patriksvensson merged 2 commits intospectreconsole:mainfrom
GrantTotinov:fix-align-measure-width

Conversation

@GrantTotinov
Copy link
Copy Markdown
Contributor

Fixes #1910

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

Changes

Align did not override the Measure method, causing it to always return maxWidth regardless of any explicitly set Width.

Added a Measure override that respects the explicitly set width, consistent with how Render already handles it.

Added regression test to ensure explicit width is enforced.


Please upvote 👍 this pull request if you are interested in it.

Copilot AI review requested due to automatic review settings April 25, 2026 03:16
@GrantTotinov
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Align measurement behavior so an explicitly set Align.Width is respected during layout/measurement (not just during rendering), addressing issue #1910 where containers like Panel could expand unexpectedly.

Changes:

  • Add Align.Measure override that clamps to Width when provided.
  • Add a unit test intended to prevent regressions around explicit width handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Spectre.Console/Widgets/Align.cs Overrides Measure to respect explicitly set Width when reporting max width.
src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs Adds a test intended to validate explicit width behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Spectre.Console/Widgets/Align.cs Outdated
Comment thread src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs Outdated
Comment thread src/Spectre.Console.Tests/Unit/Widgets/AlignTests.cs Outdated
@GrantTotinov GrantTotinov force-pushed the fix-align-measure-width branch from 067ef56 to e40d862 Compare April 25, 2026 04:09
@GrantTotinov GrantTotinov force-pushed the fix-align-measure-width branch from e40d862 to 5b66030 Compare April 25, 2026 04:47
@patriksvensson
Copy link
Copy Markdown
Contributor

Added a commit to this PR that makes the build pass.

@patriksvensson patriksvensson merged commit 5842908 into spectreconsole:main Apr 25, 2026
3 checks passed
@patriksvensson
Copy link
Copy Markdown
Contributor

Merged! Thank you for your contribution. Much appreciated! 👍

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.

Align Measure always return maxWidth even when I explicitly set Width

3 participants