pub struct RelmActionGroup<GroupName: ActionGroupName> { /* private fields */ }Expand description
A type-safe action group that wraps around gio::SimpleActionGroup.
Implementations§
Source§impl<GroupName: ActionGroupName> RelmActionGroup<GroupName>
impl<GroupName: ActionGroupName> RelmActionGroup<GroupName>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RelmActionGroup.
Examples found in repository?
relm4/examples/actions.rs (line 81)
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 (line 142)
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 }Sourcepub fn add_action<Name: ActionName>(&mut self, action: RelmAction<Name>)
pub fn add_action<Name: ActionName>(&mut self, action: RelmAction<Name>)
Add an action to the group.
Examples found in repository?
relm4/examples/actions.rs (line 82)
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 (line 143)
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 }Sourcepub fn register_for_main_application(self)
pub fn register_for_main_application(self)
Register the added actions at application level.
Sourcepub fn register_for_widget<W>(self, widget: W)
pub fn register_for_widget<W>(self, widget: W)
Register the added actions for a certain widget.
Examples found in repository?
relm4/examples/actions.rs (line 84)
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 (line 145)
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 }Sourcepub fn into_action_group(self) -> SimpleActionGroup
pub fn into_action_group(self) -> SimpleActionGroup
Convert RelmActionGroup into a gio::SimpleActionGroup.
Trait Implementations§
Source§impl<GroupName: Debug + ActionGroupName> Debug for RelmActionGroup<GroupName>
impl<GroupName: Debug + ActionGroupName> Debug for RelmActionGroup<GroupName>
Source§impl<GroupName: ActionGroupName> Default for RelmActionGroup<GroupName>
impl<GroupName: ActionGroupName> Default for RelmActionGroup<GroupName>
Source§impl<GroupName, A> FromIterator<A> for RelmActionGroup<GroupName>
impl<GroupName, A> FromIterator<A> for RelmActionGroup<GroupName>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = A>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<GroupName> Freeze for RelmActionGroup<GroupName>
impl<GroupName> RefUnwindSafe for RelmActionGroup<GroupName>where
GroupName: RefUnwindSafe,
impl<GroupName> !Send for RelmActionGroup<GroupName>
impl<GroupName> !Sync for RelmActionGroup<GroupName>
impl<GroupName> Unpin for RelmActionGroup<GroupName>where
GroupName: Unpin,
impl<GroupName> UnwindSafe for RelmActionGroup<GroupName>where
GroupName: 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