About control templates
Control templates are transparent structures that describe a control in details. A control template must
implement the
ControlTemplate
trait.
Unlike other GUI toolkit where it's possible to create controls with very little required informations
(aka sane defaults), in NWG every parameter must be defined in the template beforehand. The reason behind
that is that nowdays, GUI are mostly done though markup languages or WYSIWYG interfaces and predefined
templates make it easier to create those tools.
For a list of all built-in control template see
4. List of built-in controls .
To create a control in a Ui, the
new_control(ID, template) -> Result<ID, Error>
method must be used. If the creation
was successful, the ID that was just added is returned otherwise an
Error
enum is returned.
Arguments
- ID: The control id that will be used to represent the new control
- template: The control template
Behaviour
- When the function returns, the control is created and is visible to the user.
Failures
- If the ID is already taken a
Error::CONTROL_EXISTS
is returned
- If there was an error during the template creation a
Error::TEMPLATE_CREATION
is returned
Example:
let mut ui: Ui<&'static str> = Ui::new();
ui.new_control("MainWindow", window_template).expect("Something went wrong!");
To remove a control from a Ui, the
remove_control(ID) -> Result<Vec<ID>, Error>
method must be used.
The method return a
Vec
of all removed IDS.
Arguments
- ID: The control id that will be removed
Behaviour
- Removing a control with children also removes the children.
- For every control removed a
Event::Removed
event is sent.
- All controls are guaranteed to be perfectly alive while the removed callbacks are being executed.
Failures
- If the control id is not in the Ui a
Error::CONTROL_NOT_FOUND
is returned.
Example:
let removed_ids = ui.remove_control("MainWindow").unwrap();