Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Use correct theme colors for project headers and thread items (#62597)

roboind3ccd5719486
diff --git a/crates/agent_ui/src/threads_archive_view.rs b/crates/agent_ui/src/threads_archive_view.rs
index ca56756195b..fd1f69de8c7 100644
--- a/crates/agent_ui/src/threads_archive_view.rs
+++ b/crates/agent_ui/src/threads_archive_view.rs
@@ -619,6 +619,8 @@ impl ThreadsArchiveView {
highlight_positions,
} => {
let id = SharedString::from(format!("archive-entry-{}", ix));
+ let color = cx.theme().colors();
+ let button_hover_bg = color.element_background;
let is_focused = self.selection == Some(ix);
let is_hovered = self.hovered_index == Some(ix);
@@ -692,6 +694,7 @@ impl ThreadsArchiveView {
base.status(AgentThreadStatus::Running)
.action_slot(
IconButton::new("cancel-restore", IconName::Close)
+ .hover_background(button_hover_bg)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip(Tooltip::text("Cancel Restore"))
@@ -710,6 +713,7 @@ impl ThreadsArchiveView {
} else if is_archived {
base.action_slot(
IconButton::new("delete-thread", IconName::Trash)
+ .hover_background(button_hover_bg)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip({
@@ -748,6 +752,7 @@ impl ThreadsArchiveView {
} else {
base.action_slot(
IconButton::new("archive-thread", IconName::Archive)
+ .hover_background(button_hover_bg)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip({
diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs
index 8e934d82162..890248d674a 100644
--- a/crates/sidebar/src/sidebar.rs
+++ b/crates/sidebar/src/sidebar.rs
@@ -2340,10 +2340,18 @@ impl Sidebar {
let key_for_toggle = key.clone();
let key_for_focus = key.clone();
+ let color = cx.theme().colors();
+ let sidebar_base_bg = if is_sticky {
+ color.surface_overlay_background()
+ } else {
+ color.surface_background
+ };
+
// The fade gradient renders as a visible patch on transparent windows,
// so truncate the label instead.
- let opaque_window =
- cx.theme().window_background_appearance() == WindowBackgroundAppearance::Opaque;
+ let opaque_window = cx.theme().window_background_appearance()
+ == WindowBackgroundAppearance::Opaque
+ && sidebar_base_bg.a >= 1.0;
let label = if highlight_positions.is_empty() {
Label::new(label.clone())
@@ -2357,21 +2365,14 @@ impl Sidebar {
.into_any_element()
};
- let color = cx.theme().colors();
- let sidebar_base_bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
-
let base_bg = color.background.blend(sidebar_base_bg);
- let hover_base = color
- .element_active
- .blend(color.element_background.opacity(0.2));
- let hover_solid = base_bg.blend(hover_base);
+ let hover_solid = base_bg.blend(color.ghost_element_hover);
+ let active_solid = base_bg.blend(color.ghost_element_active);
let group_name_for_gradient = group_name.clone();
let gradient_overlay = move || {
- GradientFade::new(base_bg, hover_solid, hover_solid)
+ GradientFade::new(base_bg, hover_solid, active_solid)
.width(px(92.0))
.right(px(-2.0))
.gradient_stop(0.7)
@@ -2399,7 +2400,10 @@ impl Sidebar {
this.border_color(gpui::transparent_black())
}
})
- .when(!has_filter, |this| this.hover(|s| s.bg(hover_solid)))
+ .when(!has_filter, |this| {
+ this.hover(|s| s.bg(color.ghost_element_hover))
+ .group_active(&group_name, |s| s.bg(color.ghost_element_active))
+ })
.child(
h_flex()
.relative()
@@ -2465,22 +2469,31 @@ impl Sidebar {
.children(opaque_window.then(|| gradient_overlay()))
.child(
h_flex()
- .gap_px()
- .pr_1p5()
.children(opaque_window.then(|| gradient_overlay()))
- .child(self.render_new_thread_button(ix, id_prefix, key, &group_name, cx))
- .child(self.render_project_header_ellipsis_menu(
- ix,
- id_prefix,
- key,
- is_active,
- has_threads,
- &group_name,
- cx,
- ))
- .on_mouse_down(gpui::MouseButton::Left, |_, _, cx| {
- cx.stop_propagation();
- }),
+ .child(
+ h_flex()
+ .gap_px()
+ .pr_1p5()
+ .child(self.render_new_thread_button(
+ ix,
+ id_prefix,
+ key,
+ &group_name,
+ cx,
+ ))
+ .child(self.render_project_header_ellipsis_menu(
+ ix,
+ id_prefix,
+ key,
+ is_active,
+ has_threads,
+ &group_name,
+ cx,
+ ))
+ .on_mouse_down(gpui::MouseButton::Left, |_, _, cx| {
+ cx.stop_propagation();
+ }),
+ ),
)
.on_mouse_down(gpui::MouseButton::Right, {
let menu_handle = self
@@ -2550,6 +2563,12 @@ impl Sidebar {
SharedString::from(format!("{id_prefix}project-header-new-thread-{ix}")),
IconName::Plus,
)
+ .when(!is_menu_open && !self.has_filter_query(cx), |button| {
+ let color = cx.theme().colors();
+ button
+ .hover_background(color.element_background)
+ .active_background(color.element_active)
+ })
.selected_style(ButtonStyle::Tinted(TintColor::Accent))
.icon_size(IconSize::Small)
.when(!is_menu_open, |this| this.visible_on_hover(group_name));
@@ -2854,6 +2873,12 @@ impl Sidebar {
.with_handle(menu_handle)
.trigger(
IconButton::new(trigger_id, IconName::Ellipsis)
+ .when(!is_menu_open && !self.has_filter_query(cx), |button| {
+ let color = cx.theme().colors();
+ button
+ .hover_background(color.element_background)
+ .active_background(color.element_active)
+ })
.selected_style(ButtonStyle::Tinted(TintColor::Accent))
.icon_size(IconSize::Small)
.when(!is_menu_open, |el| el.visible_on_hover(group_name)),
@@ -3259,9 +3284,7 @@ impl Sidebar {
.unwrap_or(px(0.));
let color = cx.theme().colors();
- let background = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.2));
+ let background = color.surface_overlay_background();
let element = v_flex()
.absolute()
@@ -6250,9 +6273,9 @@ impl Sidebar {
let id = SharedString::from(format!("thread-entry-{}", ix));
let color = cx.theme().colors();
- let sidebar_bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
+ let sidebar_bg = color.surface_background;
+ let button_hover_bg = color.element_background;
+ let button_active_bg = color.element_active;
let timestamp: SharedString = if is_empty_draft {
SharedString::default()
@@ -6316,6 +6339,8 @@ impl Sidebar {
})
.when(is_hovered && !is_renaming, |this| {
let rename_button = IconButton::new(("rename-thread", ix), IconName::Pencil)
+ .hover_background(button_hover_bg)
+ .active_background(button_active_bg)
.icon_size(IconSize::Small)
.tooltip({
let focus_handle = focus_handle.clone();
@@ -6358,6 +6383,8 @@ impl Sidebar {
Some(DraftKind::Empty) => None,
Some(DraftKind::WithContent) => Some(
IconButton::new("discard_thread", IconName::Close)
+ .hover_background(button_hover_bg)
+ .active_background(button_active_bg)
.icon_size(IconSize::Small)
.tooltip(Tooltip::text("Discard Draft"))
.on_click({
@@ -6375,6 +6402,8 @@ impl Sidebar {
),
None => Some(
IconButton::new("archive-thread", IconName::Archive)
+ .hover_background(button_hover_bg)
+ .active_background(button_active_bg)
.icon_size(IconSize::Small)
.tooltip({
let focus_handle = focus_handle.clone();
@@ -6573,9 +6602,9 @@ impl Sidebar {
let timestamp = format_history_entry_timestamp(terminal.metadata.created_at);
let is_hovered = self.hovered_thread_index == Some(ix);
let color = cx.theme().colors();
- let sidebar_bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
+ let sidebar_bg = color.surface_background;
+ let button_hover_bg = color.element_background;
+ let button_active_bg = color.element_active;
let metadata = terminal.metadata.clone();
let workspace = terminal.workspace.clone();
let focus_handle = self.focus_handle.clone();
@@ -6621,6 +6650,8 @@ impl Sidebar {
.when(is_hovered && !is_renaming, |this| {
this.action_slot(
IconButton::new("close-terminal", IconName::Close)
+ .hover_background(button_hover_bg)
+ .active_background(button_active_bg)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip({
@@ -7913,9 +7944,7 @@ impl Render for Sidebar {
let sticky_header = self.render_sticky_header(window, cx);
let color = cx.theme().colors();
- let bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
+ let bg = color.surface_background;
let no_open_projects = !self.contents.has_open_projects;
let no_search_results = self.contents.entries.is_empty();
diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rs
index 941e1a3f2db..79c710930c3 100644
--- a/crates/sidebar/src/sidebar_tests.rs
+++ b/crates/sidebar/src/sidebar_tests.rs
@@ -14,7 +14,7 @@ use agent_ui::{
};
use chrono::DateTime;
use fs::{FakeFs, Fs};
-use gpui::{TestAppContext, UpdateGlobal};
+use gpui::{Bounds, Hsla, Point, Rgba, TestAppContext, UpdateGlobal, VisualTestContext};
use pretty_assertions::assert_eq;
use project::AgentId;
use settings::SettingsStore;
@@ -695,6 +695,85 @@ fn visible_entries_as_strings(
})
}
+#[gpui::test]
+async fn test_sidebar_action_hover_contrasts_with_row(cx: &mut TestAppContext) {
+ let project = init_test_project_with_agent_panel("/my-project", cx).await;
+ cx.update(|cx| AgentRegistryStore::init_test_global(cx, Vec::new()));
+ let (multi_workspace, cx) =
+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
+ let (sidebar, _panel) = setup_sidebar_with_agent_panel(&multi_workspace, cx);
+ save_n_test_threads(1, &project, cx).await;
+
+ for (query, surface_alpha) in [("my-project", 1.0), ("", 1.0), ("", 0.0), ("", 0.2)] {
+ set_sidebar_test_surface_alpha(surface_alpha, cx);
+ type_in_search(&sidebar, query, cx);
+ let row_bounds = sidebar.read_with(cx, |sidebar, _| {
+ sidebar
+ .list_state
+ .bounds_for_item(0)
+ .expect("rendered project header")
+ });
+ if query.is_empty() {
+ cx.simulate_mouse_move(row_bounds.center(), None, Modifiers::default());
+ let hover =
+ cx.update(|_, cx| u32::from(Rgba::from(cx.theme().colors().ghost_element_hover)));
+ assert_eq!(
+ sidebar_painted_background_at(row_bounds.center(), cx),
+ hover
+ );
+ }
+ for selector in ["ICON-Plus", "ICON-Ellipsis"] {
+ assert_sidebar_action_hover(selector, row_bounds, cx);
+ }
+ if query.is_empty() {
+ let thread_bounds = sidebar.read_with(cx, |sidebar, _| {
+ sidebar
+ .list_state
+ .bounds_for_item(1)
+ .expect("rendered thread")
+ });
+ for selector in ["ICON-Pencil", "ICON-Archive"] {
+ assert_sidebar_action_hover(selector, thread_bounds, cx);
+ }
+ }
+ }
+
+ sidebar.update_in(cx, |sidebar, window, cx| {
+ sidebar.show_archive(window, cx);
+ let SidebarView::Archive(archive) = &sidebar.view else {
+ panic!("Thread History should be open");
+ };
+ window.focus(&archive.focus_handle(cx), cx);
+ });
+ cx.run_until_parked();
+
+ for (archived, selector) in [(false, "ICON-Archive"), (true, "ICON-Trash")] {
+ if archived {
+ cx.update(|_, cx| {
+ ThreadMetadataStore::global(cx).update(cx, |store, cx| {
+ let thread_id = store.entries().next().expect("seeded thread").thread_id;
+ store.archive(thread_id, None, cx);
+ });
+ });
+ cx.run_until_parked();
+ }
+ cx.dispatch_action(SelectFirst);
+ let row_bounds = cx.update(|window, cx| {
+ window
+ .painted_quads()
+ .into_iter()
+ .find(|quad| quad.border_color == cx.theme().colors().panel_focused_border)
+ .expect("selected Thread History row")
+ .bounds
+ .map(|value| px(value.as_f32() / window.scale_factor()))
+ });
+ for surface_alpha in [1.0, 0.0, 0.2] {
+ set_sidebar_test_surface_alpha(surface_alpha, cx);
+ assert_sidebar_action_hover(selector, row_bounds, cx);
+ }
+ }
+}
+
#[gpui::test]
async fn test_thread_metadata_update_preserves_sticky_header_measurements(cx: &mut TestAppContext) {
let (fs, project_a) = init_multi_project_test(&["/project-a", "/project-b"], cx).await;
@@ -15732,3 +15811,59 @@ async fn test_find_or_create_workspace_returns_the_created_remote_workspace(
"the local workspace should have re-activated during the open"
);
}
+
+fn set_sidebar_test_surface_alpha(alpha: f32, cx: &mut VisualTestContext) {
+ cx.update(|window, cx| {
+ let mut theme = cx.theme().as_ref().clone();
+ theme.styles.colors.background = Hsla::from(gpui::rgb(0xdcdcdd));
+ theme.styles.colors.surface_background = Hsla::from(gpui::rgb(0xebebec)).alpha(alpha);
+ theme.styles.colors.element_background = Hsla::from(gpui::rgb(0xebebec));
+ theme.styles.colors.ghost_element_hover = Hsla::from(gpui::rgb(0xdfdfe0));
+ theme::GlobalTheme::update_theme(cx, Arc::new(theme));
+ window.refresh();
+ });
+ cx.run_until_parked();
+}
+
+fn assert_sidebar_action_hover(
+ selector: &'static str,
+ row_bounds: Bounds<Pixels>,
+ cx: &mut VisualTestContext,
+) {
+ cx.simulate_mouse_move(row_bounds.center(), None, Modifiers::default());
+ let button_bounds = cx.debug_bounds(selector).expect("visible row action");
+ assert_eq!(
+ row_bounds.intersect(&button_bounds),
+ button_bounds,
+ "{selector}: action must belong to the row"
+ );
+ cx.simulate_mouse_move(button_bounds.center(), None, Modifiers::default());
+ let background = sidebar_painted_background_at(button_bounds.center(), cx);
+ assert_ne!(
+ background,
+ sidebar_painted_background_at(row_bounds.center(), cx),
+ "{selector}: hovered action must contrast with the row"
+ );
+}
+
+fn sidebar_painted_background_at(position: Point<Pixels>, cx: &mut VisualTestContext) -> u32 {
+ cx.update(|window, _| {
+ let position = position.scale(window.scale_factor());
+ let color = window
+ .painted_quads()
+ .into_iter()
+ .filter(|quad| {
+ !quad.background.is_transparent()
+ && quad
+ .bounds
+ .intersect(&quad.content_mask.bounds)
+ .contains(&position)
+ })
+ .max_by_key(|quad| quad.order)
+ .expect("painted background at pointer")
+ .background
+ .as_solid()
+ .expect("solid background at pointer");
+ u32::from(Rgba::from(color))
+ })
+}
diff --git a/crates/theme/src/styles/colors.rs b/crates/theme/src/styles/colors.rs
index 8364994d395..c6109c1c196 100644
--- a/crates/theme/src/styles/colors.rs
+++ b/crates/theme/src/styles/colors.rs
@@ -463,6 +463,14 @@ pub enum ThemeColorField {
}
impl ThemeColors {
+ pub fn surface_overlay_background(&self) -> Hsla {
+ if self.background.a >= 1.0 || self.surface_background.a >= 1.0 {
+ self.background.blend(self.surface_background)
+ } else {
+ self.panel_overlay_background
+ }
+ }
+
pub fn color(&self, field: ThemeColorField) -> Hsla {
match field {
ThemeColorField::Border => self.border,
@@ -635,10 +643,34 @@ pub struct ThemeStyles {
#[cfg(test)]
mod tests {
+ use gpui::Rgba;
use serde_json::json;
use super::*;
+ #[test]
+ fn surface_overlay_background() {
+ let mut colors = ThemeColors::light();
+ colors.panel_overlay_background = Hsla::from(gpui::rgb(0xff0000));
+
+ for (surface, background, expected) in [
+ (0x58585a00, 0xdcdcddff, 0xdcdcddff),
+ (0x00000080, 0xdcdcddff, 0x6d6d6eff),
+ (0xebebecff, 0x24252900, 0xebebecff),
+ (0xebebec00, 0x24252900, 0xff0000ff),
+ (0xebebec00, 0x24252980, 0xff0000ff),
+ (0x24252980, 0x24252980, 0xff0000ff),
+ ] {
+ colors.surface_background = Hsla::from(gpui::rgba(surface));
+ colors.background = Hsla::from(gpui::rgba(background));
+ assert_eq!(
+ u32::from(Rgba::from(colors.surface_overlay_background())),
+ expected,
+ "surface {surface:#010x}, background {background:#010x}"
+ );
+ }
+ }
+
#[test]
fn override_a_single_theme_color() {
let mut colors = ThemeColors::light();
diff --git a/crates/ui/src/components/ai/thread_item.rs b/crates/ui/src/components/ai/thread_item.rs
index 6234407d4bb..7cf574848a8 100644
--- a/crates/ui/src/components/ai/thread_item.rs
+++ b/crates/ui/src/components/ai/thread_item.rs
@@ -251,30 +251,25 @@ impl ThreadItem {
impl RenderOnce for ThreadItem {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let color = cx.theme().colors();
+ let raw_bg = self.base_bg.unwrap_or(color.surface_background);
// The fade gradient paints a solid color over the title to blend it into
// the row background, but a transparent window has no opaque surface to
// fade into, so it renders as a visible patch; truncate the title instead.
- let opaque_window =
- cx.theme().window_background_appearance() == WindowBackgroundAppearance::Opaque;
- let sidebar_base_bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
-
- let raw_bg = self.base_bg.unwrap_or(sidebar_base_bg);
+ let opaque_window = cx.theme().window_background_appearance()
+ == WindowBackgroundAppearance::Opaque
+ && raw_bg.a >= 1.0;
let apparent_bg = color.background.blend(raw_bg);
let base_bg = if self.selected {
- apparent_bg.blend(color.element_active)
+ apparent_bg.blend(color.ghost_element_selected)
} else {
apparent_bg
};
- let hover_color = color
- .element_active
- .blend(color.element_background.opacity(0.2));
- let hover_bg = apparent_bg.blend(hover_color);
+ let hover_bg = apparent_bg.blend(color.ghost_element_hover);
+ let active_bg = apparent_bg.blend(color.ghost_element_active);
- let gradient_overlay = GradientFade::new(base_bg, hover_bg, hover_bg)
+ let gradient_overlay = GradientFade::new(base_bg, hover_bg, active_bg)
.width(px(64.0))
.right(px(-10.0))
.gradient_stop(0.7)
@@ -360,6 +355,7 @@ impl RenderOnce for ThreadItem {
} else if self.title_generating {
Label::new(title)
.color(Color::Muted)
+ .when(!opaque_window, |label| label.truncate())
.with_animation(
"generating-title",
Animation::new(Duration::from_secs(2))
@@ -434,13 +430,14 @@ impl RenderOnce for ThreadItem {
.w_full()
.py_1()
.px_1p5()
- .when(self.selected, |s| s.bg(color.element_active))
+ .when(self.selected, |s| s.bg(color.ghost_element_selected))
.border_1()
.border_r_2()
.border_color(gpui::transparent_black())
.when(self.focused, |s| s.border_color(color.panel_focused_border))
.when(self.rounded, |s| s.rounded_sm())
- .hover(|s| s.bg(hover_color))
+ .hover(|s| s.bg(color.ghost_element_hover))
+ .active(|s| s.bg(color.ghost_element_active))
.on_hover(self.on_hover)
.child(
h_flex()
@@ -466,20 +463,23 @@ impl RenderOnce for ThreadItem {
this.child(
h_flex()
.relative()
- .pr_1p5()
.when(opaque_window, |this| {
this.child(
- GradientFade::new(base_bg, hover_bg, hover_bg)
+ GradientFade::new(base_bg, hover_bg, active_bg)
.width(px(120.0))
.right(px(8.))
.gradient_stop(0.90)
.group_name("thread-item"),
)
})
- .child(slot)
- .on_mouse_down(MouseButton::Left, |_, _, cx| {
- cx.stop_propagation()
- }),
+ .child(
+ h_flex()
+ .pr_1p5()
+ .child(slot)
+ .on_mouse_down(MouseButton::Left, |_, _, cx| {
+ cx.stop_propagation()
+ }),
+ ),
)
})
}),
@@ -647,9 +647,7 @@ impl Component for ThreadItem {
fn preview(_window: &mut Window, cx: &mut App) -> AnyElement {
let color = cx.theme().colors();
- let bg = color
- .title_bar_background
- .blend(color.panel_background.opacity(0.25));
+ let bg = color.surface_background;
let container = || {
v_flex()
@@ -987,3 +985,70 @@ impl Component for ThreadItem {
.into_any_element()
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use gpui::{Background, Modifiers, TestAppContext, VisualTestContext, point};
+
+ #[gpui::test]
+ fn test_thread_action_padding_preserves_row_background(cx: &mut TestAppContext) {
+ cx.update(|cx| {
+ let settings_store = settings::SettingsStore::test(cx);
+ cx.set_global(settings_store);
+ theme_settings::init(theme::LoadThemes::JustBase, cx);
+ });
+ let (view, cx) = cx.add_window_view(|_, _| ThreadItemTestView { clicks: 0 });
+ let action_bounds = cx.debug_bounds("ACTION_SLOT").expect("action bounds");
+ let position = point(action_bounds.left() + px(2.), action_bounds.center().y);
+ cx.simulate_mouse_move(position, None, Modifiers::default());
+ let before = painted_backgrounds(cx);
+ cx.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
+ assert_eq!(painted_backgrounds(cx), before);
+ cx.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
+ assert_eq!(view.read_with(cx, |view, _| view.clicks), 0);
+
+ let position = point(px(25.), action_bounds.center().y);
+ cx.simulate_mouse_move(position, None, Modifiers::default());
+ cx.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
+ let active = cx.update(|_, cx| Background::from(cx.theme().colors().ghost_element_active));
+ assert_eq!(painted_backgrounds(cx).first(), Some(&active));
+ cx.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
+ assert_eq!(view.read_with(cx, |view, _| view.clicks), 1);
+ }
+
+ struct ThreadItemTestView {
+ clicks: usize,
+ }
+
+ impl Render for ThreadItemTestView {
+ fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
+ div().size_full().p(px(20.)).child(
+ div().w(px(400.)).child(
+ ThreadItem::new("thread", "Thread")
+ .hovered(true)
+ .action_slot(
+ div()
+ .debug_selector(|| "ACTION_SLOT".to_owned())
+ .pl(px(16.))
+ .child(
+ IconButton::new("action", IconName::Archive)
+ .on_click(|_, _, _| {}),
+ ),
+ )
+ .on_click(cx.listener(|view, _, _, _| view.clicks += 1)),
+ ),
+ )
+ }
+ }
+
+ fn painted_backgrounds(cx: &mut VisualTestContext) -> Vec<Background> {
+ cx.update(|window, _| {
+ window
+ .painted_quads()
+ .into_iter()
+ .map(|quad| quad.background)
+ .collect()
+ })
+ }
+}
diff --git a/crates/ui/src/components/button/button_like.rs b/crates/ui/src/components/button/button_like.rs
index ed77c801088..c7c96d17b8f 100644
--- a/crates/ui/src/components/button/button_like.rs
+++ b/crates/ui/src/components/button/button_like.rs
@@ -486,6 +486,8 @@ pub struct ButtonLike {
pub(super) disabled: bool,
pub(super) selected: bool,
pub(super) selected_style: Option<ButtonStyle>,
+ pub(super) hover_background: Option<Hsla>,
+ pub(super) active_background: Option<Hsla>,
pub(super) width: Option<DefiniteLength>,
pub(super) height: Option<DefiniteLength>,
pub(super) layer: Option<ElevationIndex>,
@@ -521,6 +523,8 @@ impl ButtonLike {
disabled: false,
selected: false,
selected_style: None,
+ hover_background: None,
+ active_background: None,
width: None,
height: None,
size: ButtonSize::Default,
@@ -756,6 +760,10 @@ impl RenderOnce for ButtonLike {
ButtonStyle::Outlined | ButtonStyle::OutlinedGhost | ButtonStyle::OutlinedCustom(_)
);
+ let active_background = self
+ .active_background
+ .unwrap_or_else(|| style.active(cx).background);
+
self.base
.h_flex()
.id(self.id.clone())
@@ -819,8 +827,8 @@ impl RenderOnce for ButtonLike {
})
.when(!self.disabled, |this| {
let hovered_style = style.hovered(self.layer, cx);
- let focus_color =
- |refinement: StyleRefinement| refinement.bg(hovered_style.background);
+ let hover_background = self.hover_background.unwrap_or(hovered_style.background);
+ let focus_color = |refinement: StyleRefinement| refinement.bg(hover_background);
this.cursor(self.cursor_style)
.hover(focus_color)
@@ -833,7 +841,7 @@ impl RenderOnce for ButtonLike {
this.focus_visible(focus_color)
}
})
- .active(|active| active.bg(style.active(cx).background))
+ .active(|active| active.bg(active_background))
})
.when_some(
self.on_right_click.filter(|_| !self.disabled),
diff --git a/crates/ui/src/components/button/icon_button.rs b/crates/ui/src/components/button/icon_button.rs
index c5b039532b2..d14aa46a32d 100644
--- a/crates/ui/src/components/button/icon_button.rs
+++ b/crates/ui/src/components/button/icon_button.rs
@@ -85,6 +85,16 @@ impl IconButton {
self
}
+ pub fn active_background(mut self, background: Hsla) -> Self {
+ self.base.active_background = Some(background);
+ self
+ }
+
+ pub fn hover_background(mut self, background: Hsla) -> Self {
+ self.base.hover_background = Some(background);
+ self
+ }
+
pub fn icon_color(mut self, icon_color: Color) -> Self {
self.icon_color = icon_color;
self