Struct native_windows_gui::Ui
[−]
[src]
pub struct Ui<ID: Hash + Clone + 'static> { /* fields omitted */ }
Object that manage the GUI elements
Methods
impl<ID: Hash + Clone> Ui<ID>
[src]
fn new() -> Result<Ui<ID>, Error>
Create a new Ui.
Returns Ok(ui)
if the initialization was successful
Returns Err(Error::System)
if the system could not initialize the ui
fn commit(&self) -> Result<(), Error>
Execute the NWG commands waiting in the Ui command queue in the order they were added.
Returns Ok(())
if everything was executed without Errors
Returns Err(Error)
if an error was encountered while executing the commands.
As soon as an error is found, the function will return. If there are still commands
waiting in the queue, they wont be touched.
fn pack_value<T: Into<Box<T>> + 'static>(&self, id: &ID, value: T)
Add an user value to the Ui.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Commit returns
• Error::KeyExist
if the key already exists in the ui
fn pack_control<T: ControlT<ID> + 'static>(&self, id: &ID, value: T)
Add a control to the Ui.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Commit returns
• Error::KeyExist
if the key already exists in the ui
• Error::{Any}
if the template creation fails
fn pack_resource<T: ResourceT<ID> + 'static>(&self, id: &ID, value: T)
Add a resource to the Ui.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Commit returns
• Error::KeyExist
if the key already exists in the ui
• Error::{Any}
if the template creation fails
fn unpack(&self, id: &ID)
Remove a element from the ui using its ID. The ID can identify a control, a resource or a user value.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Commit may returns:
• Error::ControlInUse
if the control callbacks are being executed
• Error::ControlInUse
if the object is currently borrowed (using ui.get or ui.get_mut)
• Error::KeyNotFound
if the id do not exists in the Ui
fn get<T: 'static>(&self, id: &ID) -> Result<Ref<Box<T>>, Error>
Return an immutable reference to the element identified by id
in the Ui.
It is required to give a type T
to this function as it is needed to cast the underlying value.
Ex: ui.get::<u32>(100)
Params:
• id: The id that identify the element in the ui
Commit may returns:
• Error::KeyNotFound
will be returned if the key was not found in the Ui
• Error::BadType
will be returned if the key exists, but the type do not match
• Error::BorrowError
will be returned if the element was already borrowed mutably
fn get_mut<T: 'static>(&self, id: &ID) -> Result<RefMut<Box<T>>, Error>
Return an mutable reference to element identified by id
in the Ui.
It is required to give a type T
to this function as it is needed to cast the underlying value.
Ex: ui.get_mut::<u32>(100)
Params:
• id: The id that identify the element in the ui
Commit may returns:
• Error::KeyNotFound
will be returned if the key was not found in the Ui
• Error::BadType
will be returned if the key exists, but the type do not match
• Error::BorrowError
will be returned if the element was already borrowed mutably
fn bind<T>(&self, id: &ID, cb_id: &ID, event: Event, cb: T) where
T: Fn(&Ui<ID>, &ID, &Event, &EventArgs) -> () + 'static,
T: Fn(&Ui<ID>, &ID, &Event, &EventArgs) -> () + 'static,
Bind/Add a callback to a control event.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Params:
• id: The id that identify the element in the ui
• cb_id: An id the identify the callback (to use with unbind)
• event: Type of event to target
• cb: The callback
Commit may returns:
• Error::EventNotSupported
if the event is not supported on the callback
• Error::ControlRequired
if the id do not indentify a control
• Error::KeyNotFound
if the id is not in the Ui.
• Error::KeyExists
if the cb_id is not unique for the event type.
• Error::ControlInUse
if NWG is currently executing the callback of the event
fn unbind(&self, id: &ID, cb_id: &ID, event: Event)
Unbind/Remove a callback to a control event.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Params:
• id: The id that identify the element in the ui
• cb_id: The id that identify the callback
• event: The type of the event to unbind
Commit may returns:
• Error::EventNotSupported
if the event is not supported on the callback
• Error::ControlRequired
if the id do not indentify a control
• Error::KeyNotFound
if the id is not in the Ui.
• Error::KeyNotFound
if the cb_id do not exist for the event
• Error::ControlInUse
if NWG is currently executing the callback of the event
fn trigger(&self, id: &ID, event: Event, event_arg: EventArgs)
Trigger the callbacks bound to a control event.
Delayed, this only registers the command in the ui message queue.
Either call ui.commit
to execute it now or wait for the command to be executed in the main event loop.
Params:
• id: The id that identify the control in the ui
• event: The type of the event to trigger
• event_arg: The arguments to send to the callbacks
Commit may returns:
• Error::EventNotSupported
if the event is not supported on the callback
• Error::ControlRequired
if the id do not indentify a control
• Error::KeyNotFound
if the id is not in the Ui.
fn handle_of(&self, id: &ID) -> Result<AnyHandle, Error>
Return the underlying handle of a control or a resource. While this method is safe, anything done with the returned handle definitely won't be.
Returns:
• Ok(AnyHandle)
if the control or the resource is found
• Error::KeyNotFound
if the id is not in the Ui.
• Error::ControlOrResourceRequired
if the id indentify a user value
• Error::BorrowError
if the element was already borrowed mutably
fn has_id(&self, id: &ID) -> bool
Check if an id exists in the ui
Params:
• id -> The ID to check
unsafe fn message_handle(&self) -> HWND
Return the message window handle of the ui. Useful for controls or functions that requires a window (such as timers)