RelmActionGroup

Struct 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>

Source

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
Hide additional 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    }
Source

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
Hide additional 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    }
Source

pub fn register_for_main_application(self)

Register the added actions at application level.

Source

pub fn register_for_widget<W>(self, widget: W)
where W: AsRef<Widget>,

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
Hide additional 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    }
Source

pub fn into_action_group(self) -> SimpleActionGroup

Trait Implementations§

Source§

impl<GroupName: Debug + ActionGroupName> Debug for RelmActionGroup<GroupName>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<GroupName: ActionGroupName> Default for RelmActionGroup<GroupName>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<GroupName, A> FromIterator<A> for RelmActionGroup<GroupName>
where A: Into<SimpleAction>, GroupName: ActionGroupName,

Source§

fn from_iter<I>(iter: I) -> Self
where 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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> AsyncPosition<()> for C

Source§

fn position(_index: usize)

Returns the position. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<C, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more