From 764275a47d9029f5f2455117d97a01c88cc1cfe1 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 3 Feb 2025 17:47:35 +0800 Subject: [PATCH] Fix menu dispatch action. --- crates/story/src/lib.rs | 8 +++++++- crates/story/src/title_bar.rs | 23 ++++++++++++++++++++++- crates/ui/src/popup_menu.rs | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/story/src/lib.rs b/crates/story/src/lib.rs index 430ddd2d..6b97beec 100644 --- a/crates/story/src/lib.rs +++ b/crates/story/src/lib.rs @@ -74,7 +74,13 @@ pub struct SelectLocale(SharedString); #[derive(Clone, PartialEq, Eq, Deserialize)] pub struct SelectFont(usize); -impl_internal_actions!(story, [SelectLocale, SelectFont, SelectScrollbarShow,]); +#[derive(Clone, PartialEq, Eq, Deserialize)] +pub struct SelectRadius(usize); + +impl_internal_actions!( + story, + [SelectLocale, SelectFont, SelectRadius, SelectScrollbarShow,] +); actions!(story, [Quit, Open, CloseWindow]); diff --git a/crates/story/src/title_bar.rs b/crates/story/src/title_bar.rs index 6d546d66..eee7cfe7 100644 --- a/crates/story/src/title_bar.rs +++ b/crates/story/src/title_bar.rs @@ -15,7 +15,7 @@ use ui::{ ActiveTheme as _, ContextModal as _, IconName, Sizable as _, Theme, TitleBar, }; -use crate::{SelectFont, SelectLocale, SelectScrollbarShow}; +use crate::{SelectFont, SelectLocale, SelectRadius, SelectScrollbarShow}; pub struct AppTitleBar { title: SharedString, @@ -230,6 +230,16 @@ impl FontSizeSelector { window.refresh(); } + fn on_select_radius( + &mut self, + radius: &SelectRadius, + window: &mut Window, + cx: &mut Context, + ) { + Theme::global_mut(cx).radius = radius.0 as f32; + window.refresh(); + } + fn on_select_scrollbar_show( &mut self, show: &SelectScrollbarShow, @@ -245,12 +255,14 @@ impl Render for FontSizeSelector { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let focus_handle = self.focus_handle.clone(); let font_size = cx.theme().font_size as i32; + let radius = cx.theme().radius as i32; let scroll_show = cx.theme().scrollbar_show; div() .id("font-size-selector") .track_focus(&focus_handle) .on_action(cx.listener(Self::on_select_font)) + .on_action(cx.listener(Self::on_select_radius)) .on_action(cx.listener(Self::on_select_scrollbar_show)) .child( Button::new("btn") @@ -266,6 +278,15 @@ impl Render for FontSizeSelector { .menu_with_check("Font Default", font_size == 16, Box::new(SelectFont(16))) .menu_with_check("Font Small", font_size == 14, Box::new(SelectFont(14))) .separator() + .menu_with_check("Radius 16px", radius == 16, Box::new(SelectRadius(16))) + .menu_with_check("Radius 8px", radius == 8, Box::new(SelectRadius(8))) + .menu_with_check( + "Radius 4px (default)", + radius == 4, + Box::new(SelectRadius(4)), + ) + .menu_with_check("Radius 0px", radius == 0, Box::new(SelectRadius(0))) + .separator() .menu_with_check( "Scrolling to show Scrollbar", scroll_show == ScrollbarShow::Scrolling, diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index e672a207..17e5c3a5 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -274,7 +274,7 @@ impl PopupMenu { window.focus(&handle); } - cx.dispatch_action(action.as_ref()); + window.dispatch_action(action.boxed_clone(), cx); }) }