Repository navigation
Headless measures text at the display's pixels per point (#273) - #275
Merged
Merged
Conversation
A Headless pass ran with egui's default scale of one pixel per point, whatever display the frame it stands in for is drawn on. egui lays glyphs out on the physical pixel grid, so a galley measured at 1.0 is a few points wider or narrower than the same text at 1.5 or 2.0: a text leaf's rect, and where its lines break, differed between Headless and the drawn frame. Headless now carries a PixelsPerPoint (finite and positive, 1.0 by default) and hands it to every pass as the root viewport's native_pixels_per_point, as kittest and eframe do. A test sets it with Headless::pixels_per_point to match the harness or display it compares against. The test lays a shadcn-styled card with a semi-bold title and a wrapping paragraph out headless and through a kittest harness at 1.0, 1.5 and 2.0 pixels per point, and holds every text leaf's rect within 0.5 pt. Without the fix it fails at 1.5 (the body 216.8 drawn, 220.0 headless). Behaviour changes: none at the default scale; new public API testing::PixelsPerPoint and Headless::pixels_per_point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
A layout given no base text measured in egui's Body even where an eggshell style was installed, so a test that left the base text out of `Headless` laid text out in another size than the app it tested. The default now follows the style an app installs: the installed `Style`'s text, in egui's text colour, else egui's Body as before. It is one fallback, shared by `Headless` and every drawn `LayoutState`, so the two still agree. Behaviour change: in a context with an eggshell style installed, a layout with no base text sets its root text in that style's `text` instead of egui's Body. Under the shadcn preset the two are the same; no golden moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
Owner
Author
|
Gate (my run on b5678c3, merged with main): |
A scale that is not finite and positive gives the default, marked TODO(#279) for the library's error channel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
samitbasu
added a commit
that referenced
this pull request
Nov 16, 2026
No textual conflicts. The new table (src/owned/table.rs) called the old `div_id_with(id, key, ..)`; it now passes a Slot (the row's own, and `slot_of` for each cell's id), so a repeated key there gets its own id like everywhere else. The merged code adds no debug-misuse panics in WP1's scope (the markdown builder's `shell()` is the builder's, which cannot panic). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
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 #273
Cause.
Headlessalways ran its passes at egui's default of 1 pixel per point. egui snaps glyphs to the physical pixel grid, so text measured at 1.0 comes out a few points wider or narrower than the same text drawn at 1.5 or 2.0. The text leaf's rect, and where its lines break, then differ between the headless layout and the drawn frame. With the scale, base text, preset and theme all matching, the two agree exactly.Fix.
Headlessnow carries atesting::PixelsPerPoint(a newtype that must be finite and positive, 1.0 by default) and passes it to every pass as the root viewport'snative_pixels_per_point, the same way kittest and eframe do. A test sets it withHeadless::pixels_per_pointto match the harness or display it compares against.Test.
headless::headless_text_wraps_as_the_drawn_frame_doeslays out a shadcn-styled card (a semi-bold title over a wrapping paragraph, in the preset's body text, light theme) two ways: headless, and through the kittest support harness. It does this at 1.0, 1.5 and 2.0 pixels per point and asserts every text leaf's rect is equal within 0.5 pt. It also asserts its preconditions: the body wraps, and it is sized to its lines rather than stretched. Without the fix it fails at 1.5 (body right edge 220.0 headless, 216.8 drawn). With the fix restored it passes.Note on the consumer's report. The consumer's test helper builds its
Headlesswithout.base_text(..), so the root text falls back to egui's Body, while the frame sets the theme's base text. On top of that, kittest'sbuild_ui_stateinsets the rootUiby an 8 pt outer margin. Either one alone shifts a wrapping card by tens of points at 1.0 pixels per point. Those differences are in the consumer's setup, not inHeadless; this PR fixes the gap that remains once the setup matches.Follow-up: the default base text (b5678c3). A layout given no base text used to fall back to egui's Body, even where an eggshell style was installed. That is the trap the consumer fell into. The default now follows the installed style: the installed
Style'stext, in egui's text colour, else egui's Body as before. It is one fallback (TextStyle::default_for, used byLayoutState::build), shared byHeadlessand every drawn layout, so the two still agree. ChangingHeadlessalone would have split them for an app that sets no base text.headless::without_a_base_text_a_layout_reads_the_installed_styleuses a style whose text is unlike Body; it failed before the change.headless::without_a_base_text_or_a_style_a_layout_reads_egui_bodychecks the unstyled case is unchanged.Note for the testing guide (#236, the user's prose). kittest's
build_ui_stateinsets the root by an 8 pt margin, so a harness's layout area is 16 pt narrower than the size it's given. AHeadlessmeant to match a kittest frame needs the inner size. This PR leaves it to the guide.Behaviour changes.
textinstead of egui's Body. Under the shadcn preset the two are the same, so no golden moved.No-panic rule (#279).
PixelsPerPoint::newasserted that the scale was finite and positive. It now falls back to 1.0 for any other scale, with a// TODO(#279): report. A test,headless::a_scale_that_is_not_finite_and_positive_falls_back_to_one, failed before the change.New public API:
testing::PixelsPerPointandHeadless::pixels_per_point.Goldens changed. None.
CI.
cargo xtask cipassed (exit 0, fuzz included).🤖 Generated with Claude Code
https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o