From 65828c14fc8574f853fe71fbc078956a36aceb0f Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 18 Oct 2023 19:12:02 -0400 Subject: [PATCH] Use ui_size to build icon button --- crates/ui2/src/components/icon_button.rs | 30 +++++++++++------------- crates/ui2/src/prelude.rs | 17 +------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index a75b9ff5ffd45fe15309575036ac48f5c22cc37b..3f41b4f5b953e89f54db58fa97aefcfcfbc3c4f1 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use gpui3::{Interactive, MouseButton}; -use crate::prelude::*; +use crate::{h_stack, prelude::*}; use crate::{theme, ClickHandler, Icon, IconColor, IconElement}; struct IconButtonHandlers { @@ -68,32 +68,30 @@ impl IconButton { fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); + let color = ThemeColor::new(cx); let icon_color = match (self.state, self.color) { (InteractionState::Disabled, _) => IconColor::Disabled, _ => self.color, }; - let mut div = div(); - if self.variant == ButtonVariant::Filled { - div = div.bg(theme.highest.on.default.background); - } + let mut button = h_stack() + .justify_center() + .rounded_md() + .py(ui_size(0.25)) + .px(ui_size(6. / 14.)) + .when(self.variant == ButtonVariant::Filled, |this| { + this.bg(color.filled_element) + }) + .hover(|style| style.bg(theme.highest.base.hovered.background)) + .child(IconElement::new(self.icon).color(icon_color)); if let Some(click_handler) = self.handlers.click.clone() { - div = div.on_mouse_down(MouseButton::Left, move |state, event, cx| { + button = button.on_mouse_down(MouseButton::Left, move |state, event, cx| { click_handler(state, cx); }); } - div.w_7() - .h_6() - .flex() - .items_center() - .justify_center() - .rounded_md() - .hover(|style| style.bg(theme.highest.base.hovered.background)) - // .active() - // .fill(theme.highest.base.pressed.background) - .child(IconElement::new(self.icon).color(icon_color)) + button } } diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index b0e02dbf1fb262603c5571f4988e7f4795e8bb82..4374fb92e9e1ffe66fddc021bdebdb1e3f2d9bcb 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -6,24 +6,9 @@ pub use gpui3::{ use crate::settings::user_settings; pub use crate::{theme, ButtonVariant, ElementExt, Theme}; -use gpui3::{hsla, rems, rgb, AbsoluteLength, Hsla, Rems}; +use gpui3::{hsla, rems, rgb, Hsla, Rems}; use strum::EnumIter; -#[derive(Clone, Copy)] -pub struct FakeSettings { - pub list_indent_depth: AbsoluteLength, - pub default_panel_size: AbsoluteLength, -} - -impl Default for FakeSettings { - fn default() -> Self { - Self { - list_indent_depth: rems(0.3).into(), - default_panel_size: AbsoluteLength::Rems(rems(16.)), - } - } -} - #[derive(Default)] pub struct SystemColor { pub transparent: Hsla,