Trait relm4::actions::traits::ActionName
source · pub trait ActionName {
type Group: ActionGroupName;
type Target;
type State;
const NAME: &'static str;
// Provided method
fn action_name() -> String { ... }
}
Expand description
Define the name of an action.
Required Associated Types§
sourcetype Group: ActionGroupName
type Group: ActionGroupName
The group of this action.
Required Associated Constants§
Provided Methods§
sourcefn action_name() -> String
fn action_name() -> String
The full action name (group.action).
Examples found in repository?
relm4/examples/actions.rs (line 61)
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 88 89 90 91 92
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 group = RelmActionGroup::<WindowActionGroup>::new();
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;
});
group.add_action(&action);
group.add_action(&action2);
let actions = group.into_action_group();
widgets
.main_window
.insert_action_group(WindowActionGroup::NAME, Some(&actions));
ComponentParts { model, widgets }
}