Struct relm4::actions::RelmActionGroup
source · 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?
examples/actions.rs (line 81)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
fn init(
_init: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let menu_model = gtk::gio::Menu::new();
menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
let model = Self { counter: 0 };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
});
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
println!("Stateful action -> state: {state}, value: {value}");
*state += value;
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
More examples
examples/menu.rs (line 142)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// ============================================================
//
// You can also use menu! outside of the widget macro.
// This is the manual equivalent to the the menu! macro above.
//
// ============================================================
//
// relm4::menu! {
// main_menu: {
// custom: "my_widget",
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// section! {
// "Section example" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// },
// section! {
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example Value" => ExampleU8Action(1_u8),
// }
// }
// };
let model = Self { counter };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = {
RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
})
};
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, _value| {
*state ^= 1;
dbg!(state);
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
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?
examples/actions.rs (line 82)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
fn init(
_init: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let menu_model = gtk::gio::Menu::new();
menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
let model = Self { counter: 0 };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
});
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
println!("Stateful action -> state: {state}, value: {value}");
*state += value;
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
More examples
examples/menu.rs (line 143)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// ============================================================
//
// You can also use menu! outside of the widget macro.
// This is the manual equivalent to the the menu! macro above.
//
// ============================================================
//
// relm4::menu! {
// main_menu: {
// custom: "my_widget",
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// section! {
// "Section example" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// },
// section! {
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example Value" => ExampleU8Action(1_u8),
// }
// }
// };
let model = Self { counter };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = {
RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
})
};
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, _value| {
*state ^= 1;
dbg!(state);
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
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?
examples/actions.rs (line 84)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
fn init(
_init: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let menu_model = gtk::gio::Menu::new();
menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
let model = Self { counter: 0 };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
});
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
println!("Stateful action -> state: {state}, value: {value}");
*state += value;
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
More examples
examples/menu.rs (line 145)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// ============================================================
//
// You can also use menu! outside of the widget macro.
// This is the manual equivalent to the the menu! macro above.
//
// ============================================================
//
// relm4::menu! {
// main_menu: {
// custom: "my_widget",
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// section! {
// "Section example" => ExampleAction,
// "Example toggle" => ExampleU8Action(1_u8),
// },
// section! {
// "Example" => ExampleAction,
// "Example2" => ExampleAction,
// "Example Value" => ExampleU8Action(1_u8),
// }
// }
// };
let model = Self { counter };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = {
RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
})
};
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, _value| {
*state ^= 1;
dbg!(state);
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
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