Skip to content

Fixes #4887 - DimAuto.Calculate wrong height for vertical text before layout#4889

Merged
tig merged 4 commits intov2_developfrom
fix/4887-dimauto-vertical-height
Apr 7, 2026
Merged

Fixes #4887 - DimAuto.Calculate wrong height for vertical text before layout#4889
tig merged 4 commits intov2_developfrom
fix/4887-dimauto-vertical-height

Conversation

@tig
Copy link
Copy Markdown
Collaborator

@tig tig commented Apr 5, 2026

Summary

  • Fix DimAuto.Calculate returning 0 for text height when TextFormatter.Direction is vertical and the view hasn't been laid out yet (Viewport.Width == 0)
  • Add tests for GetAutoWidth() / GetAutoHeight() covering horizontal, vertical, with/without border
  • Update AttributePicker to use GetAutoWidth() instead of GetWidthRequiredForSubViews() + GetAdornmentsThickness().Horizontal

Root Cause

In DimAuto.Calculate for Dimension.Height, when ConstrainToWidth is null the code uses Viewport.Width to constrain text width before measuring height. Before layout, Viewport.Width is 0, causing FormatAndGetSize(new Size(0, ...)) to return Height = 0 for any text — vertical or otherwise.

The fix uses the already-computed max-based width fallback (from line 190) when Viewport.Width is 0.

Test plan

  • 8 new GetAutoWidth/GetAutoHeight tests (3 were failing before fix)
  • All existing DimAutoTests pass
  • Full parallelizable test suite: 15503 tests, 0 regressions

Fixes #4887

🤖 Generated with Claude Code

When Viewport.Width was 0 (view not yet laid out), FormatAndGetSize was
called with zero width constraint, producing height=0 for any text. Use
the already-computed max-based width as fallback instead.

Also adds GetAutoWidth/GetAutoHeight tests and updates AttributePicker
to use GetAutoWidth() instead of GetWidthRequiredForSubViews() + thickness.

Fixes #4887

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tig tig requested a review from Copilot April 5, 2026 16:25
@tig tig changed the title Fix DimAuto.Calculate wrong height for vertical text before layout Fixes #4887 - DimAuto.Calculate wrong height for vertical text before layout Apr 5, 2026
Copy link
Copy Markdown
Contributor

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 an edge case in DimAuto.Calculate where auto height could be computed as 0 for vertical text before the first layout pass (Viewport.Width == 0), and adds/uses new helper APIs to measure a view’s auto-sized dimensions.

Changes:

  • Fix DimAuto.Calculate (height path) to avoid constraining text to width 0 before layout by falling back to the precomputed max-based width.
  • Add View.GetAutoWidth() / View.GetAutoHeight() helpers and extend Dim.AutoTests with coverage for horizontal/vertical text and borders.
  • Update AttributePicker to size _styleSelector via GetAutoWidth().

Reviewed changes

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

File Description
Terminal.Gui/ViewBase/Layout/DimAuto.cs Fixes pre-layout text height measurement by avoiding a zero-width constraint.
Terminal.Gui/ViewBase/View.Content.cs Adds GetAutoWidth() / GetAutoHeight() and refactors required-size helpers to use them.
Terminal.Gui/Views/Color/AttributePicker.cs Switches style selector sizing to the new auto-size helper API.
Tests/UnitTestsParallelizable/ViewBase/Layout/Dim.AutoTests.cs Adds test coverage for GetAutoWidth() / GetAutoHeight() including vertical text + border cases.

Comment thread Terminal.Gui/ViewBase/View.Content.cs Outdated
Comment thread Terminal.Gui/ViewBase/View.Content.cs
Comment thread Tests/UnitTestsParallelizable/ViewBase/Layout/Dim.AutoTests.cs
@tig tig merged commit 2f171a1 into v2_develop Apr 7, 2026
16 of 18 checks passed
@tig tig deleted the fix/4887-dimauto-vertical-height branch April 7, 2026 15:50
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.

DimAuto.Calculate returns wrong height for vertical text when Viewport.Width is 0

2 participants