Control

Trait Control 

Source
pub trait Control:
    BaseControl
    + Deref<Target = Widget>
    + DerefMut {
    // Required methods
    fn query_component(&self, type_id: TypeId) -> Option<&dyn Any>;
    fn handle_routed_message(
        &mut self,
        ui: &mut UserInterface,
        message: &mut UiMessage,
    );

    // Provided methods
    fn resolve(&mut self, _node_map: &NodeHandleMapping) { ... }
    fn on_remove(&self, _sender: &Sender<UiMessage>) { ... }
    fn measure_override(
        &self,
        ui: &UserInterface,
        available_size: Vector2<f32>,
    ) -> Vector2<f32> { ... }
    fn arrange_override(
        &self,
        ui: &UserInterface,
        final_size: Vector2<f32>,
    ) -> Vector2<f32> { ... }
    fn draw(&self, _drawing_context: &mut DrawingContext) { ... }
    fn update(&mut self, _dt: f32, _sender: &Sender<UiMessage>) { ... }
    fn preview_message(&self, _ui: &UserInterface, _message: &mut UiMessage) { ... }
    fn handle_os_event(
        &mut self,
        _self_handle: Handle<UiNode>,
        _ui: &mut UserInterface,
        _event: &OsEvent,
    ) { ... }
}
Expand description

Trait for all UI controls in library.

Required Methods§

Source

fn query_component(&self, type_id: TypeId) -> Option<&dyn Any>

Allows a widget to provide access to inner components. For example you can build your custom MyTree widget using engine’s Tree widget as a base. The engine needs to know whether the custom widget is actually extends functionality of some existing widget.

§Implementation

It should at least return Some(self) for type_id == TypeId::of::<Self>.

Source

fn handle_routed_message( &mut self, ui: &mut UserInterface, message: &mut UiMessage, )

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§

Source

fn resolve(&mut self, _node_map: &NodeHandleMapping)

Source

fn on_remove(&self, _sender: &Sender<UiMessage>)

Source

fn measure_override( &self, ui: &UserInterface, available_size: Vector2<f32>, ) -> Vector2<f32>

Source

fn arrange_override( &self, ui: &UserInterface, final_size: Vector2<f32>, ) -> Vector2<f32>

Source

fn draw(&self, _drawing_context: &mut DrawingContext)

Source

fn update(&mut self, _dt: f32, _sender: &Sender<UiMessage>)

Source

fn preview_message(&self, _ui: &UserInterface, _message: &mut UiMessage)

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.

Source

fn handle_os_event( &mut self, _self_handle: Handle<UiNode>, _ui: &mut UserInterface, _event: &OsEvent, )

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.

§Important notes

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

Implementors§

Source§

impl Control for Border

Source§

impl Control for Button

Source§

impl Control for Canvas

Source§

impl Control for CheckBox

Source§

impl Control for AlphaBar

Source§

impl Control for ColorField

Source§

impl Control for ColorPicker

Source§

impl Control for HueBar

Source§

impl Control for SaturationBrightnessField

Source§

impl Control for CurveEditor

Source§

impl Control for Decorator

Source§

impl Control for DockingManager

Source§

impl Control for Tile

Source§

impl Control for DropdownList

Source§

impl Control for Expander

Source§

impl Control for FileBrowser

Source§

impl Control for FileSelector

Source§

impl Control for Grid

Source§

impl Control for Image

Source§

impl Control for ArrayEditor

Source§

impl Control for CollectionEditor

Source§

impl Control for Inspector

Source§

impl Control for ListView

Source§

impl Control for ListViewItem

Source§

impl Control for Menu

Source§

impl Control for MenuItem

Source§

impl Control for MessageBox

Source§

impl Control for Popup

Source§

impl Control for ProgressBar

Source§

impl Control for ScrollBar

Source§

impl Control for ScrollPanel

Source§

impl Control for ScrollViewer

Source§

impl Control for StackPanel

Source§

impl Control for TabControl

Source§

impl Control for Text

Source§

impl Control for TextBox

Source§

impl Control for Tree

Source§

impl Control for TreeRoot

Source§

impl Control for VectorImage

Source§

impl Control for Window

Source§

impl Control for WrapPanel

Source§

impl<T> Control for RangeEditor<T>
where T: NumericType,

Source§

impl<T> Control for RectEditor<T>
where T: NumericType,

Source§

impl<T: InspectableEnum> Control for EnumPropertyEditor<T>

Source§

impl<T: NumericType> Control for NumericUpDown<T>

Source§

impl<T: NumericType> Control for Vec2Editor<T>

Source§

impl<T: NumericType> Control for Vec3Editor<T>

Source§

impl<T: NumericType> Control for Vec4Editor<T>