gpui: Fix hover styles not being applied during layout#43324
gpui: Fix hover styles not being applied during layout#43324mikayla-maki merged 1 commit intozed-industries:mainfrom
Conversation
Here is the example I useduse 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 card = rgb(0x1a1a1a);
let card_hover = rgb(0x292929);
let primary = rgb(0xf0ab75);
let accent = rgb(0xe78fdf);
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(rgb(0x141414))
.text_color(rgb(0xfcfcfc))
.text_sm()
.child(
div()
.flex()
.flex_col()
.gap_2()
.child(div().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()
.hover(|style| style.text_color(accent).bg(card_hover))
.child("To Accent"),
),
)
.child(
div()
.flex()
.flex_col()
.gap_2()
.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()
.hover(|style| style.text_color(primary).bg(card_hover))
.active(|style| style.text_color(accent).bg(card_hover))
.child("To Primary on hover, to Accent on click"),
),
)
.child(
div().flex().flex_col().gap_2().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()
.text_color(rgb(0xd6d6dc))
.hover(|style| style.bg(card_hover))
.flex()
.flex_col()
.gap_2()
.child(div().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()
.hover(|style| style.text_color(primary))
.group_hover("my-group", |style| style.text_color(accent))
.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()
.group_hover("my-group", |style| style.text_color(primary))
.child("To Primary on parent hover"),
),
),
)
.child(
div()
.flex()
.flex_col()
.gap_2()
.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)
.hover(|style| style.text_color(accent).bg(card_hover))
.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)
.hover(|style| style.text_color(primary).bg(card_hover))
.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();
});
} |
|
Ah I see, thanks! Will checkout the related |
|
I think that what you've noticed with the text size changing is probably the same bug as in my PR here: #42852 |
|
Yeah, I think it's the same bug @/Serophots. |
282c74d to
ed3d668
Compare
|
@errmayank Yes, now is fixed. |
|
Thanks! |
|
@errmayank looks like there's still some problems #43214 (comment) |
|
@mikayla-maki created a separate issue #45436 for tracking. Potential fix in |
|
Heya — I think either this PR or #45437 introduced a regression. In the agent panel, the
This fixes the problem and I'm happy to push if it makes sense, but just wanted to give a shout out here before I do it in case these changes cause any other side effect I'm not aware of (I haven't seen anything visible while playing with it). |
Closes #43214 Release Notes: - Fixed GPUI hover styles not being applied during layout Here's the before/after: https://github.com/user-attachments/assets/5b1828bb-234a-493b-a33d-368ca01a773b
Tackling this as I noticed a bug in the agent panel where the button to delete a thread, which appeared only on hover, stopped showing up. PRs #43324 and #45437 fixed stuff in applying hover styles through `.hover()` but broke the `.on_hover()` callback. Problem was that both methods were sharing the same `element_state.hover_state` but running at different phases. The solution here was to add a new independent state field for the hover listener (`hover_listener_state`) while the hover style method keeps using `hover_state`. Release Notes: - Agent: Fixed a bug where the button to delete a thread stopped showing up.
Tackling this as I noticed a bug in the agent panel where the button to delete a thread, which appeared only on hover, stopped showing up. PRs #43324 and #45437 fixed stuff in applying hover styles through `.hover()` but broke the `.on_hover()` callback. Problem was that both methods were sharing the same `element_state.hover_state` but running at different phases. The solution here was to add a new independent state field for the hover listener (`hover_listener_state`) while the hover style method keeps using `hover_state`. Release Notes: - Agent: Fixed a bug where the button to delete a thread stopped showing up.
#46831) Cherry-pick of #46371 to stable ---- Tackling this as I noticed a bug in the agent panel where the button to delete a thread, which appeared only on hover, stopped showing up. PRs #43324 and #45437 fixed stuff in applying hover styles through `.hover()` but broke the `.on_hover()` callback. Problem was that both methods were sharing the same `element_state.hover_state` but running at different phases. The solution here was to add a new independent state field for the hover listener (`hover_listener_state`) while the hover style method keeps using `hover_state`. Release Notes: - Agent: Fixed a bug where the button to delete a thread stopped showing up. Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
…s#43324) Closes zed-industries#43214 Release Notes: - Fixed GPUI hover styles not being applied during layout Here's the before/after: https://github.com/user-attachments/assets/5b1828bb-234a-493b-a33d-368ca01a773b
…s#43324) Closes zed-industries#43214 Release Notes: - Fixed GPUI hover styles not being applied during layout Here's the before/after: https://github.com/user-attachments/assets/5b1828bb-234a-493b-a33d-368ca01a773b
…s#43324) Closes zed-industries#43214 Release Notes: - Fixed GPUI hover styles not being applied during layout Here's the before/after: https://github.com/user-attachments/assets/5b1828bb-234a-493b-a33d-368ca01a773b



Closes #43214
Release Notes:
Here's the before/after:
screen-recording-gpui-hover.mov