Use ui_size to build icon button

Nate Butler created

Change summary

crates/ui2/src/components/icon_button.rs | 30 ++++++++++++-------------
crates/ui2/src/prelude.rs                | 17 -------------
2 files changed, 15 insertions(+), 32 deletions(-)

Detailed changes

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<S: 'static + Send + Sync> {
@@ -68,32 +68,30 @@ impl<S: 'static + Send + Sync> IconButton<S> {
 
     fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
         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
     }
 }

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,