diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 67ac608..e93a103 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,3 +4,6 @@ pub mod common; #[cfg(feature = "button")] pub mod button; + +#[cfg(feature = "checkbox")] +pub mod checkbox; diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index 0adcd83..fc77b0d 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -55,6 +55,8 @@ impl Global for Theme {} /// Corner radii components paint from; grows one class at a time. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Radius { + /// Small controls: checkbox and radio indicators. + pub sm: Pixels, pub control: Pixels, /// Pill and circle shapes. pub full: Pixels, @@ -63,6 +65,7 @@ pub struct Radius { impl Default for Radius { fn default() -> Self { Self { + sm: px(4.), control: px(6.), full: px(9999.), } diff --git a/crates/theme/src/resolve.rs b/crates/theme/src/resolve.rs index 0343835..67ffce8 100644 --- a/crates/theme/src/resolve.rs +++ b/crates/theme/src/resolve.rs @@ -221,6 +221,7 @@ mod tests { assert_eq!(resolved.colors.accent, base.accent); assert_eq!(resolved.ramps.primary.base, base.primary); assert_eq!(resolved.ramps.secondary.base, base.secondary); + assert_eq!(resolved.radius.sm, px(4.)); assert_eq!(resolved.radius.control, px(6.)); } } diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 93fbef2..b76e228 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -5,6 +5,7 @@ use gpui::{ WindowBounds, WindowOptions, div, px, size, }; use gpui_native_core::button::{Button, ButtonVariant}; +use gpui_native_core::checkbox::Checkbox; use gpui_native_core::common::{h_flex, v_flex}; use gpui_native_icons::{IconAssets, IconRole, icon}; use gpui_native_theme::{ActiveTheme as _, Theme}; @@ -12,6 +13,7 @@ use gpui_platform::application; struct Gallery { button_clicks: usize, + checkbox_checked: bool, } impl Render for Gallery { @@ -198,6 +200,39 @@ impl Render for Gallery { .child(format!("clicked {} times", self.button_clicks)), ), ) + .child( + v_flex() + .gap_2() + .child(section_label( + "checkbox · native refs — NSButton (checkbox), WinUI CheckBox, Adwaita CheckButton, Breeze", + colors, + )) + .child( + v_flex().gap_2().child({ + let gallery = gallery.clone(); + Checkbox::new("gallery-checkbox") + .label("Enable telemetry") + .checked(self.checkbox_checked) + .on_change(move |checked, _, cx| { + gallery.update(cx, |gallery, cx| { + gallery.checkbox_checked = checked; + cx.notify(); + }); + }) + }) + .child( + Checkbox::new("gallery-checkbox-disabled-off") + .label("Disabled unchecked") + .disabled(true), + ) + .child( + Checkbox::new("gallery-checkbox-disabled-on") + .label("Disabled checked") + .checked(true) + .disabled(true), + ), + ), + ) .child( div() .flex() @@ -347,7 +382,10 @@ fn main() { cx.refresh_windows(); }) .detach(); - cx.new(|_| Gallery { button_clicks: 0 }) + cx.new(|_| Gallery { + button_clicks: 0, + checkbox_checked: false, + }) }, ) { eprintln!("failed to open gallery window: {err}");