pub struct RelmAction<Name: ActionName> { /* private fields */ }Expand description
A type safe action that wraps around gio::SimpleAction.
Implementations§
Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Sourcepub fn new_stateful_with_target_value<Callback: Fn(&SimpleAction, &mut Name::State, Name::Target) + 'static>(
start_value: &Name::State,
callback: Callback,
) -> Self
pub fn new_stateful_with_target_value<Callback: Fn(&SimpleAction, &mut Name::State, Name::Target) + 'static>( start_value: &Name::State, callback: Callback, ) -> Self
Create a new stateful action with target value.
Examples found in repository?
relm4/examples/actions.rs (lines 76-79)
55 fn init(
56 _init: Self::Init,
57 root: Self::Root,
58 sender: ComponentSender<Self>,
59 ) -> ComponentParts<Self> {
60 let menu_model = gtk::gio::Menu::new();
61 menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
62
63 let model = Self { counter: 0 };
64
65 let widgets = view_output!();
66
67 let app = relm4::main_application();
68 app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
69
70 let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
71 println!("Statelesss action!");
72 sender.input(Msg::Increment);
73 });
74
75 let action2: RelmAction<ExampleU8Action> =
76 RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
77 println!("Stateful action -> state: {state}, value: {value}");
78 *state += value;
79 });
80
81 let mut group = RelmActionGroup::<WindowActionGroup>::new();
82 group.add_action(action);
83 group.add_action(action2);
84 group.register_for_widget(&widgets.main_window);
85
86 ComponentParts { model, widgets }
87 }More examples
relm4/examples/menu.rs (lines 137-140)
93 fn init(
94 counter: Self::Init,
95 root: Self::Root,
96 sender: ComponentSender<Self>,
97 ) -> ComponentParts<Self> {
98 // ============================================================
99 //
100 // You can also use menu! outside of the widget macro.
101 // This is the manual equivalent to the the menu! macro above.
102 //
103 // ============================================================
104 //
105 // relm4::menu! {
106 // main_menu: {
107 // custom: "my_widget",
108 // "Example" => ExampleAction,
109 // "Example2" => ExampleAction,
110 // "Example toggle" => ExampleU8Action(1_u8),
111 // section! {
112 // "Section example" => ExampleAction,
113 // "Example toggle" => ExampleU8Action(1_u8),
114 // },
115 // section! {
116 // "Example" => ExampleAction,
117 // "Example2" => ExampleAction,
118 // "Example Value" => ExampleU8Action(1_u8),
119 // }
120 // }
121 // };
122
123 let model = Self { counter };
124 let widgets = view_output!();
125
126 let app = relm4::main_application();
127 app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
128
129 let action: RelmAction<ExampleAction> = {
130 RelmAction::new_stateless(move |_| {
131 println!("Statelesss action!");
132 sender.input(Msg::Increment);
133 })
134 };
135
136 let action2: RelmAction<ExampleU8Action> =
137 RelmAction::new_stateful_with_target_value(&0, |_, state, _value| {
138 *state ^= 1;
139 dbg!(state);
140 });
141
142 let mut group = RelmActionGroup::<WindowActionGroup>::new();
143 group.add_action(action);
144 group.add_action(action2);
145 group.register_for_widget(&widgets.main_window);
146
147 ComponentParts { model, widgets }
148 }Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Sourcepub fn new_stateful<Callback: Fn(&SimpleAction, &mut Name::State) + 'static>(
start_value: &Name::State,
callback: Callback,
) -> Self
pub fn new_stateful<Callback: Fn(&SimpleAction, &mut Name::State) + 'static>( start_value: &Name::State, callback: Callback, ) -> Self
Create a new stateful action.
Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Sourcepub fn new_with_target_value<Callback: Fn(&SimpleAction, Name::Target) + 'static>(
callback: Callback,
) -> Self
pub fn new_with_target_value<Callback: Fn(&SimpleAction, Name::Target) + 'static>( callback: Callback, ) -> Self
Create a new stateless action with a target value.
Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Sourcepub fn new_stateless<Callback: Fn(&SimpleAction) + 'static>(
callback: Callback,
) -> Self
pub fn new_stateless<Callback: Fn(&SimpleAction) + 'static>( callback: Callback, ) -> Self
Create a new stateless action.
Examples found in repository?
relm4/examples/actions.rs (lines 70-73)
55 fn init(
56 _init: Self::Init,
57 root: Self::Root,
58 sender: ComponentSender<Self>,
59 ) -> ComponentParts<Self> {
60 let menu_model = gtk::gio::Menu::new();
61 menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
62
63 let model = Self { counter: 0 };
64
65 let widgets = view_output!();
66
67 let app = relm4::main_application();
68 app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
69
70 let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
71 println!("Statelesss action!");
72 sender.input(Msg::Increment);
73 });
74
75 let action2: RelmAction<ExampleU8Action> =
76 RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
77 println!("Stateful action -> state: {state}, value: {value}");
78 *state += value;
79 });
80
81 let mut group = RelmActionGroup::<WindowActionGroup>::new();
82 group.add_action(action);
83 group.add_action(action2);
84 group.register_for_widget(&widgets.main_window);
85
86 ComponentParts { model, widgets }
87 }More examples
relm4/examples/menu.rs (lines 130-133)
93 fn init(
94 counter: Self::Init,
95 root: Self::Root,
96 sender: ComponentSender<Self>,
97 ) -> ComponentParts<Self> {
98 // ============================================================
99 //
100 // You can also use menu! outside of the widget macro.
101 // This is the manual equivalent to the the menu! macro above.
102 //
103 // ============================================================
104 //
105 // relm4::menu! {
106 // main_menu: {
107 // custom: "my_widget",
108 // "Example" => ExampleAction,
109 // "Example2" => ExampleAction,
110 // "Example toggle" => ExampleU8Action(1_u8),
111 // section! {
112 // "Section example" => ExampleAction,
113 // "Example toggle" => ExampleU8Action(1_u8),
114 // },
115 // section! {
116 // "Example" => ExampleAction,
117 // "Example2" => ExampleAction,
118 // "Example Value" => ExampleU8Action(1_u8),
119 // }
120 // }
121 // };
122
123 let model = Self { counter };
124 let widgets = view_output!();
125
126 let app = relm4::main_application();
127 app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
128
129 let action: RelmAction<ExampleAction> = {
130 RelmAction::new_stateless(move |_| {
131 println!("Statelesss action!");
132 sender.input(Msg::Increment);
133 })
134 };
135
136 let action2: RelmAction<ExampleU8Action> =
137 RelmAction::new_stateful_with_target_value(&0, |_, state, _value| {
138 *state ^= 1;
139 dbg!(state);
140 });
141
142 let mut group = RelmActionGroup::<WindowActionGroup>::new();
143 group.add_action(action);
144 group.add_action(action2);
145 group.register_for_widget(&widgets.main_window);
146
147 ComponentParts { model, widgets }
148 }Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Create a menu item for this action with the target value sent to the action on activation.
Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Create a menu item for this action.
Source§impl<Name: ActionName> RelmAction<Name>
impl<Name: ActionName> RelmAction<Name>
Sourcepub fn set_enabled(&self, enabled: bool)
pub fn set_enabled(&self, enabled: bool)
Sets the action as enabled or disabled.
If disabled, the action cannot be activated anymore.
Sourcepub fn gio_action(&self) -> &SimpleAction
pub fn gio_action(&self) -> &SimpleAction
Returns the inner gio::SimpleAction.
This method is meant for low level control. Only use it if you know exactly what you are doing.
Trait Implementations§
Source§impl<Name: ActionName> Clone for RelmAction<Name>
impl<Name: ActionName> Clone for RelmAction<Name>
Source§impl<Name: ActionName> Debug for RelmAction<Name>
impl<Name: ActionName> Debug for RelmAction<Name>
Source§impl<Name: ActionName> From<RelmAction<Name>> for SimpleAction
impl<Name: ActionName> From<RelmAction<Name>> for SimpleAction
Source§fn from(value: RelmAction<Name>) -> Self
fn from(value: RelmAction<Name>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<Name> Freeze for RelmAction<Name>
impl<Name> RefUnwindSafe for RelmAction<Name>where
Name: RefUnwindSafe,
impl<Name> !Send for RelmAction<Name>
impl<Name> !Sync for RelmAction<Name>
impl<Name> Unpin for RelmAction<Name>where
Name: Unpin,
impl<Name> UnwindSafe for RelmAction<Name>where
Name: UnwindSafe,
Blanket Implementations§
Source§impl<C> AsyncPosition<()> for C
impl<C> AsyncPosition<()> for C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more