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