From d86d9192c0a5604543cdca88b8121596164b0975 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 28 Oct 2026 19:29:55 +0700 Subject: [PATCH] add toggle and link --- crates/core/src/lib.rs | 6 ++++ examples/gallery/src/main.rs | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 22cc22c..5058af2 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -13,3 +13,9 @@ pub mod switch; #[cfg(feature = "radio")] pub mod radio; + +#[cfg(feature = "toggle")] +pub mod toggle; + +#[cfg(feature = "link")] +pub mod link; diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 34ff1bb..15bb052 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -7,8 +7,10 @@ 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::link::Link; use gpui_native_core::radio::{Radio, RadioGroup}; use gpui_native_core::switch::Switch; +use gpui_native_core::toggle::Toggle; use gpui_native_icons::{IconAssets, IconRole, icon}; use gpui_native_theme::{ActiveTheme as _, Theme}; use gpui_platform::application; @@ -18,6 +20,7 @@ struct Gallery { checkbox_checked: bool, switch_checked: bool, plan: SharedString, + toggle_pressed: bool, } impl Render for Gallery { @@ -296,6 +299,69 @@ impl Render for Gallery { ) }), ) + .child( + v_flex() + .gap_2() + .child(section_label( + "toggle · native refs — NSButton (toggle), WinUI ToggleButton, Adwaita ToggleButton, Breeze", + colors, + )) + .child( + h_flex().gap_2().child({ + let gallery = gallery.clone(); + Toggle::new("gallery-toggle") + .label("Bold") + .pressed(self.toggle_pressed) + .on_change(move |pressed, _, cx| { + gallery.update(cx, |gallery, cx| { + gallery.toggle_pressed = pressed; + cx.notify(); + }); + }) + }) + .child( + Toggle::new("gallery-toggle-disabled") + .label("Disabled") + .pressed(true) + .disabled(true), + ), + ), + ) + .child( + v_flex() + .gap_2() + .child(section_label( + "link · native refs — NSTextView links, WinUI HyperlinkButton, Adwaita LinkButton, Breeze", + colors, + )) + .child( + h_flex() + .gap_4() + .child( + Link::new("gallery-link-github") + .label("gpui on GitHub") + .href("https://github.com/zed-industries/zed"), + ) + .child({ + let gallery = gallery.clone(); + Link::new("gallery-link-override") + .label("On-click override") + .href("https://example.com/never-opened") + .on_click(move |_, _, cx| { + gallery.update(cx, |gallery, cx| { + gallery.button_clicks += 1; + cx.notify(); + }); + }) + }) + .child( + Link::new("gallery-link-disabled") + .label("Disabled") + .href("https://example.com/disabled") + .disabled(true), + ), + ), + ) .child( div() .flex() @@ -450,6 +516,7 @@ fn main() { checkbox_checked: false, switch_checked: true, plan: SharedString::from("starter"), + toggle_pressed: false, }) }, ) {