Fixes #4887 - DimAuto.Calculate wrong height for vertical text before layout#4889
Merged
tig merged 4 commits intov2_developfrom Apr 7, 2026
Merged
Fixes #4887 - DimAuto.Calculate wrong height for vertical text before layout#4889tig merged 4 commits intov2_developfrom
tig merged 4 commits intov2_developfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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 width0before layout by falling back to the precomputed max-based width. - Add
View.GetAutoWidth()/View.GetAutoHeight()helpers and extendDim.AutoTestswith coverage for horizontal/vertical text and borders. - Update
AttributePickerto size_styleSelectorviaGetAutoWidth().
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. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DimAuto.Calculatereturning 0 for text height whenTextFormatter.Directionis vertical and the view hasn't been laid out yet (Viewport.Width == 0)GetAutoWidth()/GetAutoHeight()covering horizontal, vertical, with/without borderAttributePickerto useGetAutoWidth()instead ofGetWidthRequiredForSubViews() + GetAdornmentsThickness().HorizontalRoot Cause
In
DimAuto.CalculateforDimension.Height, whenConstrainToWidthis null the code usesViewport.Widthto constrain text width before measuring height. Before layout,Viewport.Widthis 0, causingFormatAndGetSize(new Size(0, ...))to returnHeight = 0for any text — vertical or otherwise.The fix uses the already-computed max-based
widthfallback (from line 190) whenViewport.Widthis 0.Test plan
GetAutoWidth/GetAutoHeighttests (3 were failing before fix)DimAutoTestspassFixes #4887
🤖 Generated with Claude Code