Skip to content

fix: honour Style height, maxHeight and valign - #148

Merged
meszmate merged 1 commit into
mainfrom
fix/style-height-ignored
Sep 3, 2026
Merged

meszmate merged 1 commit into
mainfrom
fix/style-height-ignored

Conversation

@meszmate

@meszmate meszmate commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Fixes #147.

writeStyledContent worked out inner_height and 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. maxHeight and valign were dead for the same reason. It is most obvious when a style is sized from a flex .fill rect, 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 to valign, and content that overflows the box has its tail dropped. height only grows the box, so taller content is not silently cut off, and maxHeight is 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 .fill rect 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.zig and examples/flex_layout.zig already called .height() and were quietly broken, and their panels now fill their rectangles exactly.

Adds 13 tests. Full suite passes, examples build, zig fmt clean. Also wrote the sizing rules down in REFERENCE.md since they were never documented, which is the ambiguity the issue ran into.

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.
@meszmate
meszmate merged commit a015967 into main Sep 3, 2026
12 checks passed
@meszmate
meszmate deleted the fix/style-height-ignored branch September 3, 2026 07:57
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.

Style height is ignored

1 participant