refactor(menu): remove redundant entity argument on MenuActions

This commit is contained in:
Michael Aaron Murphy 2024-05-20 00:50:17 +02:00
parent b3bce0740e
commit 31ea71deef
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 6 additions and 10 deletions

View file

@ -31,7 +31,7 @@ use crate::widget::segmented_button::Entity;
/// impl MenuAction for MyAction { /// impl MenuAction for MyAction {
/// type Message = MyMessage; /// type Message = MyMessage;
/// ///
/// fn message(&self, entity: Option<Entity>) -> Self::Message { /// fn message(&self) -> Self::Message {
/// match self { /// match self {
/// MyAction::Open => MyMessage::Open, /// MyAction::Open => MyMessage::Open,
/// MyAction::Save => MyMessage::Save, /// MyAction::Save => MyMessage::Save,
@ -46,12 +46,8 @@ pub trait MenuAction: Clone + Copy + Eq + PartialEq {
/// Returns a message of type `Self::Message` when the action is triggered. /// Returns a message of type `Self::Message` when the action is triggered.
/// ///
/// # Arguments
///
/// * `entity` - An optional `Entity` that may be associated with the action.
///
/// # Returns /// # Returns
/// ///
/// * `Self::Message` - The message that is produced when the action is triggered. /// * `Self::Message` - The message that is produced when the action is triggered.
fn message(&self, entity: Option<Entity>) -> Self::Message; fn message(&self) -> Self::Message;
} }

View file

@ -225,7 +225,7 @@ where
Element<'a, Message, crate::Theme, Renderer>: From<widget::button::Button<'a, Message>>, Element<'a, Message, crate::Theme, Renderer>: From<widget::button::Button<'a, Message>>,
{ {
fn find_key<A: MenuAction>(action: &A, key_binds: &HashMap<KeyBind, A>) -> String { fn find_key<A: MenuAction>(action: &A, key_binds: &HashMap<KeyBind, A>) -> String {
for (key_bind, key_action) in key_binds.iter() { for (key_bind, key_action) in key_binds {
if action == key_action { if action == key_action {
return key_bind.to_string(); return key_bind.to_string();
} }
@ -248,12 +248,12 @@ where
widget::horizontal_space(Length::Fill), widget::horizontal_space(Length::Fill),
widget::text(key), widget::text(key),
) )
.on_press(action.message(None)); .on_press(action.message());
trees.push(MenuTree::<Message, Renderer>::new(menu_button)); trees.push(MenuTree::<Message, Renderer>::new(menu_button));
} }
MenuItem::CheckBox(label, value, action) => { MenuItem::CheckBox(label, value, action) => {
let key = find_key(&action, &key_binds); let key = find_key(&action, key_binds);
trees.push(MenuTree::new( trees.push(MenuTree::new(
menu_button!( menu_button!(
if value { if value {
@ -267,7 +267,7 @@ where
widget::horizontal_space(Length::Fill), widget::horizontal_space(Length::Fill),
widget::text(key) widget::text(key)
) )
.on_press(action.message(None)), .on_press(action.message()),
)); ));
} }
MenuItem::Folder(label, children) => { MenuItem::Folder(label, children) => {