add switch

This commit is contained in:
2026-10-28 19:04:42 +07:00
parent 1ddc10cae4
commit 0924d1d301
4 changed files with 292 additions and 0 deletions
+36
View File
@@ -7,6 +7,7 @@ use gpui::{
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::switch::Switch;
use gpui_native_icons::{IconAssets, IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, Theme};
use gpui_platform::application;
@@ -14,6 +15,7 @@ use gpui_platform::application;
struct Gallery {
button_clicks: usize,
checkbox_checked: bool,
switch_checked: bool,
}
impl Render for Gallery {
@@ -233,6 +235,39 @@ impl Render for Gallery {
),
),
)
.child(
v_flex()
.gap_2()
.child(section_label(
"switch · native refs — NSSwitch, WinUI ToggleSwitch, Adwaita Switch, Breeze Switch",
colors,
))
.child(
v_flex().gap_2().child({
let gallery = gallery.clone();
Switch::new("gallery-switch")
.label("Wi-Fi")
.checked(self.switch_checked)
.on_change(move |checked, _, cx| {
gallery.update(cx, |gallery, cx| {
gallery.switch_checked = checked;
cx.notify();
});
})
})
.child(
Switch::new("gallery-switch-disabled-off")
.label("Disabled off")
.disabled(true),
)
.child(
Switch::new("gallery-switch-disabled-on")
.label("Disabled on")
.checked(true)
.disabled(true),
),
),
)
.child(
div()
.flex()
@@ -385,6 +420,7 @@ fn main() {
cx.new(|_| Gallery {
button_clicks: 0,
checkbox_checked: false,
switch_checked: true,
})
},
) {