Repository navigation
Add a scoped style: b.styled(edit, body) (#355) - #358
Merged
Merged
Conversation
A region of a page can now have a style of its own, as the user decided for #352: Typeset restyles its page's tables and rich text without touching the rest of the app. `b.styled(edit, body)` builds `body` with the style there, changed by `edit`. Design (A): the style travels with each node where its inherited text style already does: the builder holds `&Arc<Style>`, every node records its `Arc`, and measure and draw read the node's. A scope clones the style once per frame and creates no node; nested scopes start from the one around them. Public readers, for widgets inside and outside core: `Builder::style`, `NodeUi::node_style`, `Measure::style`. Every library control now reads the scoped style where it read `Style::of(b.ctx())`; the library's own drawing (focus ring, inline-code tints, selection colour, now per node) reads the node's. Left on the context's style on purpose: font faces (fonts are context-wide), tooltip timing (one state machine a frame), and tooltip content, which is built from the root at the frame's end. `TableStyle` gains `cell_padding_y`, `header_padding_y`, `first_column_inset` and `rule_below_last`, all off by default, for typeset's tables. Breaking: `widget::Stock::size` and `sizing::Sizer::new` take the style, so a stock widget sizes with the style it is built in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
This was referenced Nov 18, 2026
Owner
Author
This was referenced Nov 18, 2026
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 #355.
This adds a scoped style:
b.styled(edit, body)buildsbodywith a style of its own, which is the style there changed byedit. Every node and control inside is built, measured and drawn with it. Nothing outside changes, and a nested scope starts from the one around it. It's design (A) from the review: every node carries its style explicitly, with no hidden "current style" slot. #352 (Typeset) builds on it to restyle a page's tables and rich text.API (for review)
The readers are public, so widgets outside core (the planned widgets crate) read the same style as core's own controls do.
How the style flows
Builderholdsstyle: &Arc<Style>beside its inherited text style.Style::of(ctx)once per frame.styledclones the style once per scope per frame, appliesedit, and lends the newArctobody. It creates no node, askeyed_underdoesn't.Arc, which costs one refcount per node, inside a scope or not.ArcreachesMeasureand the library's own text measuring. Spans lay out with the node'srich, and stock widgets size with the node's input metrics.Arc. The library's drawing reads it: the focus ring, inline-code tints, and the text selection colour, which is now per node instead of one per frame. Draw closures read it throughNodeUi::node_style.b.style()where it readStyle::of(b.ctx()): button, checkbox, select, slider, switch, stepper, field box, menu, table, segmented, radio, progress, splitter, scroll bars, mount, text field and tooltip triggers.Still the context's style, on purpose
Style::faces): fonts are registered context-wide in egui, so a scope can't change which faces exist. Face resolution and the symbol-font install read the context's style.styled's docs say so.style.tooltip.delayandgrace): one state machine per frame serves every tooltip.TableStyle: new fields for #352All are optional or default to today's look, so the shadcn table is unchanged.
cell_padding_y: Option<f32>cell_paddingheader_padding_y: Option<f32>header_heightfirst_column_inset: Option<f32>cell_padding(zero is flush)rule_below_last: boolBreaking changes
widget::Stock::size(&self, ctx, text, width)gains a style:size(&self, ctx, text, style: &Arc<Style>, width). A stock widget must size with the style it's built in, for example a text field's input metrics inside a scope.Stock::measurepasses the leaf's style. In the repo, only test implementations and callers needed it.sizing::Sizer::new(ctx, text)gains the style the same way.Tests
tests/it/styled.rs, through the real build, measure and draw:a_table_inside_styled_takes_the_override_and_one_outside_does_not: the cell heights differ by exactly the padding change, and the context's style is untouched.a_nested_scope_edits_the_style_of_the_one_around_it: an inner+= 10lands on the outer scope's 20.rich_text_inside_styled_is_measured_and_drawn_with_the_override: inline code's padding (layout space, so measure) widens the paragraph, and the link colour (draw) is the scope's inside and the context's outside.a_draw_closure_reads_the_style_its_node_was_built_in:NodeUi::node_styleinside and outside a scope.tests/it/table.rs::spacing, each set throughstyled:cell_padding_y_sets_a_body_cells_top_and_bottom_only;header_padding_y_sizes_the_header_by_its_text;a_first_column_inset_moves_only_the_first_columns_text, which covers the header too;rule_below_last_rules_off_the_last_row, which also checks it's off by default.Mutations, each caught:
rich: the rich test fails.rich: the rich test fails.Style::of(b.ctx()): 6 tests fail.support::galleys_ofis new (every galley with a text), andgalley_ofnow uses it.Prose for you
TODO(prose)placeholders:Builder::style,Builder::styled(with a doctest),NodeUi::node_style(with a doctest) andMeasure::style;TableStylefields.git diff origin/main HEAD --statcargo xtask ciexits 0 on a816158 (main cb0c520).🤖 Generated with Claude Code
https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP