Skip to content

Commit

Permalink
Fix menu dispatch action.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Feb 3, 2025
1 parent eaec664 commit 764275a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/story/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
23 changes: 22 additions & 1 deletion crates/story/src/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -230,6 +230,16 @@ impl FontSizeSelector {
window.refresh();
}

fn on_select_radius(
&mut self,
radius: &SelectRadius,
window: &mut Window,
cx: &mut Context<Self>,
) {
Theme::global_mut(cx).radius = radius.0 as f32;
window.refresh();
}

fn on_select_scrollbar_show(
&mut self,
show: &SelectScrollbarShow,
Expand All @@ -245,12 +255,14 @@ impl Render for FontSizeSelector {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> 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")
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/popup_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl PopupMenu {
window.focus(&handle);
}

cx.dispatch_action(action.as_ref());
window.dispatch_action(action.boxed_clone(), cx);
})
}

Expand Down

0 comments on commit 764275a

Please sign in to comment.