Use ui_size to build icon button

This commit is contained in:
Nate Butler 2023-10-18 19:12:02 -04:00
parent 7cb00aeb34
commit 65828c14fc
2 changed files with 15 additions and 32 deletions

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use gpui3::{Interactive, MouseButton}; use gpui3::{Interactive, MouseButton};
use crate::prelude::*; use crate::{h_stack, prelude::*};
use crate::{theme, ClickHandler, Icon, IconColor, IconElement}; use crate::{theme, ClickHandler, Icon, IconColor, IconElement};
struct IconButtonHandlers<S: 'static + Send + Sync> { 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> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let color = ThemeColor::new(cx);
let icon_color = match (self.state, self.color) { let icon_color = match (self.state, self.color) {
(InteractionState::Disabled, _) => IconColor::Disabled, (InteractionState::Disabled, _) => IconColor::Disabled,
_ => self.color, _ => self.color,
}; };
let mut div = div(); let mut button = h_stack()
if self.variant == ButtonVariant::Filled { .justify_center()
div = div.bg(theme.highest.on.default.background); .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() { 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); click_handler(state, cx);
}); });
} }
div.w_7() button
.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))
} }
} }

View file

@ -6,24 +6,9 @@ pub use gpui3::{
use crate::settings::user_settings; use crate::settings::user_settings;
pub use crate::{theme, ButtonVariant, ElementExt, Theme}; 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; 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)] #[derive(Default)]
pub struct SystemColor { pub struct SystemColor {
pub transparent: Hsla, pub transparent: Hsla,