Trait rg3d_ui::Control[][src]

pub trait Control<M, C>: 'static + Deref<Target = Widget<M, C>> + DerefMut + Clone where
    M: MessageData,
    C: Control<M, C>, 
{ fn handle_routed_message(
        &mut self,
        ui: &mut UserInterface<M, C>,
        message: &mut UiMessage<M, C>
    ); fn resolve(&mut self, _node_map: &NodeHandleMapping<M, C>) { ... }
fn measure_override(
        &self,
        ui: &UserInterface<M, C>,
        available_size: Vector2<f32>
    ) -> Vector2<f32> { ... }
fn arrange_override(
        &self,
        ui: &UserInterface<M, C>,
        final_size: Vector2<f32>
    ) -> Vector2<f32> { ... }
fn draw(&self, _drawing_context: &mut DrawingContext) { ... }
fn update(&mut self, _dt: f32) { ... }
fn preview_message(
        &self,
        _ui: &UserInterface<M, C>,
        _message: &mut UiMessage<M, C>
    ) { ... }
fn handle_os_event(
        &mut self,
        _self_handle: Handle<UINode<M, C>>,
        _ui: &mut UserInterface<M, C>,
        _event: &OsEvent
    ) { ... }
fn remove_ref(&mut self, _handle: Handle<UINode<M, C>>) { ... } }
Expand description

Trait for all UI controls in library.

Required methods

Performs event-specific actions. Must call widget.handle_message()!

Notes

Do not try to borrow node by self_handle in UI - at this moment node has been moved out of pool and attempt of borrowing will cause panic! self_handle should be used only to check if event came from/for this node or to capture input on node.

Provided methods

Used to react to a message (by producing another message) that was posted outside of current hierarchy. In other words this method is used when you need to “peek” a message before it’ll be passed into bubbling router. Most common use case is to catch messages from popups: popup in 99.9% cases is a child of root canvas and it won’t receive a message from a its logical parent during bubbling message routing. For example preview_message used in a dropdown list: dropdown list has two separate parts - a field with selected value and a popup for all possible options. Visual parent of the popup in this case is the root canvas, but logical parent is the dropdown list. Because of this fact, the field won’t receive any messages from popup, to solve this we use preview_message. This method is much more restrictive - it does not allow you to modify a node and ui, you can either request changes by sending a message or use internal mutability (Cell, RefCell, etc).

Important notes

Due to performance reasons, you must set .with_preview_messages(true) in widget builder to force library to call preview_message!

The order of execution of this method is undefined! There is no guarantee that it will be called hierarchically as widgets connected.

Provides a way to respond to OS specific events. Can be useful to detect if a key or mouse button was pressed. This method significantly differs from handle_message because os events are not dispatched - they’ll be passed to this method in any case.

Called when a node is deleted from container thus giving a chance to remove dangling handles which may cause panic.

Implementors