add checkbox
This commit is contained in:
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user