add checkbox
This commit is contained in:
@@ -4,3 +4,6 @@ pub mod common;
|
|||||||
|
|
||||||
#[cfg(feature = "button")]
|
#[cfg(feature = "button")]
|
||||||
pub mod button;
|
pub mod button;
|
||||||
|
|
||||||
|
#[cfg(feature = "checkbox")]
|
||||||
|
pub mod checkbox;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ impl Global for Theme {}
|
|||||||
/// Corner radii components paint from; grows one class at a time.
|
/// Corner radii components paint from; grows one class at a time.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct Radius {
|
pub struct Radius {
|
||||||
|
/// Small controls: checkbox and radio indicators.
|
||||||
|
pub sm: Pixels,
|
||||||
pub control: Pixels,
|
pub control: Pixels,
|
||||||
/// Pill and circle shapes.
|
/// Pill and circle shapes.
|
||||||
pub full: Pixels,
|
pub full: Pixels,
|
||||||
@@ -63,6 +65,7 @@ pub struct Radius {
|
|||||||
impl Default for Radius {
|
impl Default for Radius {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
sm: px(4.),
|
||||||
control: px(6.),
|
control: px(6.),
|
||||||
full: px(9999.),
|
full: px(9999.),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,7 @@ mod tests {
|
|||||||
assert_eq!(resolved.colors.accent, base.accent);
|
assert_eq!(resolved.colors.accent, base.accent);
|
||||||
assert_eq!(resolved.ramps.primary.base, base.primary);
|
assert_eq!(resolved.ramps.primary.base, base.primary);
|
||||||
assert_eq!(resolved.ramps.secondary.base, base.secondary);
|
assert_eq!(resolved.ramps.secondary.base, base.secondary);
|
||||||
|
assert_eq!(resolved.radius.sm, px(4.));
|
||||||
assert_eq!(resolved.radius.control, px(6.));
|
assert_eq!(resolved.radius.control, px(6.));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use gpui::{
|
|||||||
WindowBounds, WindowOptions, div, px, size,
|
WindowBounds, WindowOptions, div, px, size,
|
||||||
};
|
};
|
||||||
use gpui_native_core::button::{Button, ButtonVariant};
|
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_core::common::{h_flex, v_flex};
|
||||||
use gpui_native_icons::{IconAssets, IconRole, icon};
|
use gpui_native_icons::{IconAssets, IconRole, icon};
|
||||||
use gpui_native_theme::{ActiveTheme as _, Theme};
|
use gpui_native_theme::{ActiveTheme as _, Theme};
|
||||||
@@ -12,6 +13,7 @@ use gpui_platform::application;
|
|||||||
|
|
||||||
struct Gallery {
|
struct Gallery {
|
||||||
button_clicks: usize,
|
button_clicks: usize,
|
||||||
|
checkbox_checked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Gallery {
|
impl Render for Gallery {
|
||||||
@@ -198,6 +200,39 @@ impl Render for Gallery {
|
|||||||
.child(format!("clicked {} times", self.button_clicks)),
|
.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(
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
@@ -347,7 +382,10 @@ fn main() {
|
|||||||
cx.refresh_windows();
|
cx.refresh_windows();
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
cx.new(|_| Gallery { button_clicks: 0 })
|
cx.new(|_| Gallery {
|
||||||
|
button_clicks: 0,
|
||||||
|
checkbox_checked: false,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
eprintln!("failed to open gallery window: {err}");
|
eprintln!("failed to open gallery window: {err}");
|
||||||
|
|||||||
Reference in New Issue
Block a user