Skip to content

Conversation

@Serophots
Copy link
Contributor

Motivating problem

The gpui API currently has this counter intuitive behaviour

 div()
            .id("hallo")
            .cursor_pointer()
            .text_color(white())
            .font_weight(FontWeight::SEMIBOLD)
            .text_size(px(20.0))
            .child("hallo")
            .active(|this| this.text_color(red()))

By changing the text_color when the div is active, the current behaviour is to overwrite all of the text styling rather than do a proper refinement of the existing text styling leading to this odd result:
The button being active inadvertently changes the font size.

Screen.Recording.2025-11-16.at.10.51.32.pm.mov

Solution

Previously refining a Style would not recursively refine the TextStyle inside of it, leading to this behaviour:

let mut style = Style::default();
style.refine(&StyleRefinement::default().text_size(px(20.0)));
style.refine(&StyleRefinement::default().font_weight(FontWeight::SEMIBOLD));

assert!(style.text_style().unwrap().font_size.is_none());
//assertion passes

(As best as I can tell) Style deliberately has pub text: TextStyleRefinement storing the TextStyleRefinement rather than the absolute TextStyle so that these refinements can be elsewhere used in cascading text styles down to element's children. But a consequence of that is that the refine macro was not properly recursively refining the text field as it ought to.

I've modified the refine macro so that the #[refineable] attribute works with TextStyleRefinement as well as the usual TextStyle. (Perhaps a little bit haphazardly by simply checking whether the name ends in Refinement - there may be a better solution there).

This PR resolves the motivating problem and triggers the assertion in the above code as you'd expect. I've compiled zed under these changes and all seems to be in order there.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 17, 2025
@mikayla-maki
Copy link
Member

Please add a small GPUI test showing that this fixes the problem, perhaps in styled.rs? Or style.rs?

@maxdeviant maxdeviant changed the title GPUI: Refining a Style proprely refines the TextStyle gpui: Make refining a Style properly refine the TextStyle Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants