About actions
Actions what NWG uses to do stuff on controls during the execution of the program. Actions are sent
through the Ui, then the Ui dispatches the action to the targeted control. After execution of the action
by the control, an
ActionReturn is returned.
The max size of an Action/ActionReturn is 16 bytes. If the action arguments are bigger than 8 bytes, they
are boxed. To keep the code readable, NWG has the
nwg::actions::helper
module to generate
these complex actions.
For a list of all built-in actions see
5. List of actions .
To execute an action the
exec(ID, action) -> Result<ActionReturn, Error>
method must be used.
The ActionReturn value returned depends on the action sent.
Arguments
- ID: The control id that will execute the action
- action: The action to execute
Behaviour
- If the action is not supposed to return something
ActionReturn::None
is returned
- If the action is not supported on the control, the returned value is a
ActionReturn::NotSupported
- If the action was executed, but the result is a failure a
ActionReturn::Error
is returned
Failures
- If the control id is not in the Ui a
Error::CONTROL_NOT_FOUND
is returned.
Example
if let Ok(ActionReturn::Text(name)) = ui.exec("Name", Action::GetText) {
let msg = nwg::actions::helper::message(
"Hello!", format!("Hello {}!", name),
MessageButtons::Ok, MessageIcons::None
);
ui.exec("MainWindow", msg).unwrap();
}