fix: honour Style height, maxHeight and valign - #148
Merged
Merged
Conversation
writeStyledContent computed inner_height and then discarded it, so a style's height was never reflected in the rendered block: the content lines were emitted as-is. maxHeight and valign were dead for the same reason. The symptom is most visible when a style is sized from a flex `.fill` rect - the block collapses to the height of its text instead of filling the row it was given. Fit the content block to inner_height instead: pad short content with blank rows placed according to align_vertical, and drop the tail of content that exceeds the box. height only ever grows the box (taller content is not silently cut off); maxHeight is the clamp that truncates. Inline output is a single row, so the fill is skipped there. The content box is also now at least one row tall, matching the fact that a render always emits a line even for empty text.
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.
Fixes #147.
writeStyledContentworked outinner_heightand then discarded it with_ = inner_height, so the content lines went out as-is and a style's height never showed up in the output.maxHeightandvalignwere dead for the same reason. It is most obvious when a style is sized from a flex.fillrect, since the block collapses to the height of its text instead of filling the row it was handed.The content block is now fitted to
inner_height: short content gets blank rows placed according tovalign, and content that overflows the box has its tail dropped.heightonly grows the box, so taller content is not silently cut off, andmaxHeightis the clamp that truncates. Inline output is a single row so the fill is skipped there. The content box is also at least one row tall now, which matches the fact that a render always emits a line even for empty text.Verified the snippet from the issue: a 20x6
.fillrect now renders 20x6 instead of 20x1. A sweep over 2250 combinations of text, height, maxHeight, padding, border and valign gives the expected row count and a uniform line width every time.examples/layers.zigandexamples/flex_layout.zigalready called.height()and were quietly broken, and their panels now fill their rectangles exactly.Adds 13 tests. Full suite passes, examples build,
zig fmtclean. Also wrote the sizing rules down in REFERENCE.md since they were never documented, which is the ambiguity the issue ran into.