Skip to content

Conversation

@errmayank
Copy link
Contributor

@errmayank errmayank commented Nov 22, 2025

Closes #43214

Release Notes:

  • Fixed GPUI hover styles not being applied during layout

Here's the before/after:

screen-recording-gpui-hover.mov

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 22, 2025
@errmayank
Copy link
Contributor Author

Here is the example I used
use gpui::{
    AppContext, Application, Bounds, Context, InteractiveElement, IntoElement, ParentElement,
    Render, StatefulInteractiveElement, Styled, Window, WindowBounds, WindowOptions, div, px, rgb,
    size,
};

struct App {}

impl Render for App {
    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
        let background = rgb(0x141414);
        let foreground = rgb(0xfcfcfc);

        let card = rgb(0x1a1a1a);
        let card_foreground = rgb(0xd6d6dc);
        let card_hover = rgb(0x292929);

        let primary = rgb(0xf0ab75);
        let accent = rgb(0xe78fdf);

        let text_base = px(14.0);
        let leading_base = px(20.0);
        let border = rgb(0x4d4d4d);

        let h_card = px(60.);
        let h_item = px(40.);
        let h_label = px(24.);

        div()
            .flex()
            .flex_col()
            .size_full()
            .gap_4()
            .p_6()
            .bg(background)
            .text_color(foreground)
            .child(
                div()
                    .flex()
                    .flex_col()
                    .gap_2()
                    .child(
                        div()
                            .text_size(text_base)
                            .line_height(leading_base)
                            .child("Basic Hover"),
                    )
                    .child(
                        div()
                            .id("test-1")
                            .w_full()
                            .h(h_card)
                            .p_4()
                            .flex()
                            .items_center()
                            .bg(card)
                            .border_1()
                            .border_color(border)
                            .rounded_lg()
                            .text_color(foreground)
                            .text_size(text_base)
                            .line_height(leading_base)
                            .hover(|style| {
                                style
                                    .text_color(accent)
                                    .bg(card_hover)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                            })
                            .child("To Accent"),
                    ),
            )
            .child(
                div()
                    .flex()
                    .flex_col()
                    .gap_2()
                    .child(
                        div()
                            .text_size(text_base)
                            .line_height(leading_base)
                            .text_color(foreground)
                            .child("Hover + Active"),
                    )
                    .child(
                        div()
                            .id("test-2")
                            .w_full()
                            .h(h_card)
                            .p_4()
                            .flex()
                            .items_center()
                            .bg(card)
                            .border_1()
                            .border_color(border)
                            .rounded_lg()
                            .text_color(foreground)
                            .text_size(text_base)
                            .line_height(leading_base)
                            .hover(|style| {
                                style
                                    .text_color(primary)
                                    .bg(card_hover)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                            })
                            .active(|style| {
                                style
                                    .text_color(accent)
                                    .bg(card_hover)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                            })
                            .child("To Primary on hover, to Accent on click"),
                    ),
            )
            .child(
                div()
                    .flex()
                    .flex_col()
                    .gap_2()
                    .child(
                        div()
                            .text_size(text_base)
                            .line_height(leading_base)
                            .text_color(foreground)
                            .child("Group Hover"),
                    )
                    .child(
                        div()
                            .id("group-parent")
                            .group("my-group")
                            .w_full()
                            .min_h(px(140.))
                            .p_4()
                            .bg(card)
                            .border_1()
                            .border_color(border)
                            .rounded_lg()
                            .hover(|style| style.bg(card_hover))
                            .flex()
                            .flex_col()
                            .gap_2()
                            .child(
                                div()
                                    .text_color(card_foreground)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                                    .h(h_label)
                                    .child("Parent hover"),
                            )
                            .child(
                                div()
                                    .id("group-child-1")
                                    .h(h_item)
                                    .p_2()
                                    .flex()
                                    .items_center()
                                    .bg(card)
                                    .border_1()
                                    .border_color(border)
                                    .rounded_md()
                                    .text_color(card_foreground)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                                    .hover(|style| {
                                        style
                                            .text_color(primary)
                                            .text_size(text_base)
                                            .line_height(leading_base)
                                    })
                                    .group_hover("my-group", |style| {
                                        style
                                            .text_color(accent)
                                            .text_size(text_base)
                                            .line_height(leading_base)
                                    })
                                    .child("To Accent on parent hover, to Primary on hover"),
                            )
                            .child(
                                div()
                                    .id("group-child-2")
                                    .h(h_item)
                                    .p_2()
                                    .flex()
                                    .items_center()
                                    .bg(card)
                                    .border_1()
                                    .border_color(border)
                                    .rounded_md()
                                    .text_color(card_foreground)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                                    .group_hover("my-group", |style| {
                                        style
                                            .text_color(primary)
                                            .text_size(text_base)
                                            .line_height(leading_base)
                                    })
                                    .child("To Primary on parent hover"),
                            ),
                    ),
            )
            .child(
                div()
                    .flex()
                    .flex_col()
                    .gap_2()
                    .child(
                        div()
                            .text_size(text_base)
                            .line_height(leading_base)
                            .text_color(foreground)
                            .child("Nested Independent Hovers"),
                    )
                    .child(
                        div()
                            .flex()
                            .gap_2()
                            .w_full()
                            .h(h_card)
                            .child(
                                div()
                                    .id("nested-1")
                                    .flex_1()
                                    .h_full()
                                    .p_4()
                                    .flex()
                                    .items_center()
                                    .justify_center()
                                    .bg(card)
                                    .border_1()
                                    .border_color(border)
                                    .rounded_lg()
                                    .text_color(primary)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                                    .hover(|style| {
                                        style
                                            .text_color(accent)
                                            .bg(card_hover)
                                            .text_size(text_base)
                                            .line_height(leading_base)
                                    })
                                    .child("Primary to Accent"),
                            )
                            .child(
                                div()
                                    .id("nested-2")
                                    .flex_1()
                                    .h_full()
                                    .p_4()
                                    .flex()
                                    .items_center()
                                    .justify_center()
                                    .bg(card)
                                    .border_1()
                                    .border_color(border)
                                    .rounded_lg()
                                    .text_color(accent)
                                    .text_size(text_base)
                                    .line_height(leading_base)
                                    .hover(|style| {
                                        style
                                            .text_color(primary)
                                            .bg(card_hover)
                                            .text_size(text_base)
                                            .line_height(leading_base)
                                    })
                                    .child("Accent to Primary"),
                            ),
                    ),
            )
    }
}

fn main() {
    Application::new().run(|cx| {
        let bounds = Bounds::centered(None, size(px(700.), px(600.0)), cx);
        cx.open_window(
            WindowOptions {
                window_bounds: Some(WindowBounds::Windowed(bounds)),
                ..Default::default()
            },
            |_window, cx| cx.new(|_cx| App {}),
        )
        .unwrap();
    });
}

@maxdeviant maxdeviant changed the title gpui: Fix hover styles not applied during layout gpui: Fix hover styles not being applied during layout Nov 22, 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.

GPUI: Text color change on hover not working

2 participants