diff --git a/crates/core/src/alert.rs b/crates/core/src/alert.rs index c60d6af..8eeaee6 100644 --- a/crates/core/src/alert.rs +++ b/crates/core/src/alert.rs @@ -183,7 +183,7 @@ impl RenderOnce for Alert { Button::new((self.id.clone(), "alert-close")) .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .accessibility_label("Dismiss") .on_click(move |_, _window, cx| on_dismiss(cx)) }); diff --git a/crates/core/src/common.rs b/crates/core/src/common.rs index 7a078f3..7110ad1 100644 --- a/crates/core/src/common.rs +++ b/crates/core/src/common.rs @@ -24,6 +24,14 @@ pub trait Sizable: Sized { /// Applies the size to the component's fields. fn apply_size(&mut self, size: Size); + /// Sets `Size::XSmall`. + fn xsmall(self) -> Self + where + Self: Sized, + { + self.with_size(Size::XSmall) + } + /// Sets `Size::Small`. fn small(self) -> Self where diff --git a/crates/core/src/dialog.rs b/crates/core/src/dialog.rs index af6903b..a135332 100644 --- a/crates/core/src/dialog.rs +++ b/crates/core/src/dialog.rs @@ -245,7 +245,7 @@ impl RenderOnce for Dialog { Button::new("dialog-close") .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .debug_selector(|| "dialog-close".to_string()) .accessibility_label("Close") .on_click({ diff --git a/crates/core/tests/sizing.rs b/crates/core/tests/sizing.rs index 87ae5a6..ca8a648 100644 --- a/crates/core/tests/sizing.rs +++ b/crates/core/tests/sizing.rs @@ -5,28 +5,44 @@ use gpui::{ VisualTestContext, Window, div, px, size, }; use gpui_native_core::button::Button; +use gpui_native_core::common::Sizable as _; use gpui_native_theme::Theme; struct Harness; impl Render for Harness { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { - div().size_full().child( - Button::new("height-probe") - .label("Probe") - .debug_selector(|| "height-probe".to_string()), - ) + div() + .size_full() + .flex() + .flex_col() + .gap_2() + .child( + Button::new("height-probe") + .label("Probe") + .debug_selector(|| "height-probe".to_string()), + ) + .child( + Button::new("xsmall-height-probe") + .label("Probe") + .xsmall() + .debug_selector(|| "xsmall-height-probe".to_string()), + ) } } #[gpui::test] -fn medium_button_renders_at_the_token_height(cx: &mut TestAppContext) { +fn buttons_render_at_their_token_heights(cx: &mut TestAppContext) { cx.update(Theme::init); let window = cx.open_window(size(px(400.), px(400.)), |_, _| Harness); let mut cx = VisualTestContext::from_window(window.into(), cx); cx.run_until_parked(); - let bounds = cx.debug_bounds("height-probe").expect("button laid out"); + let medium = cx.debug_bounds("height-probe").expect("button laid out"); + let xsmall = cx + .debug_bounds("xsmall-height-probe") + .expect("xsmall button laid out"); - assert_eq!(bounds.size.height, px(32.0)); + assert_eq!(medium.size.height, px(32.0)); + assert_eq!(xsmall.size.height, px(24.0)); } diff --git a/crates/data/src/tabs.rs b/crates/data/src/tabs.rs index 3fb13d1..3ea361b 100644 --- a/crates/data/src/tabs.rs +++ b/crates/data/src/tabs.rs @@ -1201,7 +1201,7 @@ impl Tab { Button::new((self.key.clone(), "tab-close")) .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .tab_stop(false) .debug_selector({ let tabs_id = tabs_id.clone(); diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index 9186519..2f3f65d 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -169,6 +169,7 @@ impl ThemeVariant { /// A named control size class. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum Size { + XSmall, Small, /// The default. #[default] @@ -496,6 +497,7 @@ pub struct ControlMetrics { /// The control metrics for every size class. #[derive(Clone, Copy, Debug, PartialEq)] pub struct SizeTable { + pub xsmall: ControlMetrics, pub small: ControlMetrics, pub medium: ControlMetrics, pub large: ControlMetrics, @@ -522,6 +524,25 @@ impl SizeTable { switch_knob: f32, } + let xsmall = ClassFactors { + control_height: 1.5, + input_height: 1.5, + padding_x: 0.375, + text_size: 0.75, + icon_size: 0.75, + dense_icon_size: 0.625, + indicator_size: 0.75, + avatar_size: 1.25, + caption_size: 0.625, + dense_padding_x: 0.375, + plate_inset: 0.0625, + strip_height: 1.5, + menu_item_height: 1.5, + switch_height: 1.0, + switch_width: 1.75, + switch_knob: 0.625, + }; + let small = ClassFactors { control_height: 1.75, input_height: 1.75, @@ -599,6 +620,7 @@ impl SizeTable { }; Self { + xsmall: metrics(&xsmall), small: metrics(&small), medium: metrics(&medium), large: metrics(&large), @@ -608,6 +630,7 @@ impl SizeTable { /// The metrics for `size`. pub fn resolve(&self, size: Size) -> ControlMetrics { match size { + Size::XSmall => self.xsmall, Size::Small => self.small, Size::Medium => self.medium, Size::Large => self.large, diff --git a/crates/theme/src/resolve.rs b/crates/theme/src/resolve.rs index 241976f..69b59ef 100644 --- a/crates/theme/src/resolve.rs +++ b/crates/theme/src/resolve.rs @@ -293,6 +293,19 @@ mod tests { assert_eq!(resolved.sizes.medium.control_height, px(32.)); assert_eq!(resolved.sizes.medium.input_height, px(32.)); assert_eq!(resolved.sizes.medium.text_size, px(14.)); + assert_eq!(resolved.sizes.xsmall.control_height, px(24.)); + assert_eq!(resolved.sizes.xsmall.input_height, px(24.)); + assert_eq!(resolved.sizes.xsmall.text_size, px(12.)); + assert_eq!(resolved.sizes.xsmall.icon_size, px(12.)); + assert_eq!(resolved.sizes.xsmall.indicator_size, px(12.)); + assert_eq!(resolved.sizes.xsmall.avatar_size, px(20.)); + assert_eq!(resolved.sizes.xsmall.caption_size, px(10.)); + assert_eq!(resolved.sizes.xsmall.dense_padding_x, px(6.)); + assert_eq!(resolved.sizes.xsmall.plate_inset, px(1.)); + assert_eq!(resolved.sizes.xsmall.menu_item_height, px(24.)); + assert_eq!(resolved.sizes.xsmall.switch_height, px(16.)); + assert_eq!(resolved.sizes.xsmall.switch_width, px(28.)); + assert_eq!(resolved.sizes.xsmall.switch_knob, px(10.)); assert_eq!(resolved.sizes.small.control_height, px(28.)); assert_eq!(resolved.sizes.small.text_size, px(12.)); assert_eq!(resolved.sizes.small.avatar_size, px(24.));