[−][src]Macro gtk_macros::stateful_action
Create a new stateful action
-
Before:
Example:
let actions = gio::SimpleActionGroup::new(); let is_dark_mode = false; let action = gio::SimpleAction::new_stateful("dark-mode", None, &is_dark_mode.to_variant()); action.connect_activate(move |action, _| { let state = action.state().unwrap(); let action_state: bool = state.get().unwrap(); let is_dark_mode = !action_state; action.set_state(&is_dark_mode.to_variant()); }); actions.add_action(&action);
-
After:
Example:
let actions = gio::SimpleActionGroup::new(); let is_dark_mode = false; stateful_action!(actions, "dark-mode", is_dark_mode, move |action, _| { let state = action.state().unwrap(); let action_state: bool = state.get().unwrap(); let is_dark_mode = !action_state; action.set_state(&is_dark_mode.to_variant()); // Store the state using gsettings for example });