Trait rg3d_ui::Control [−][src]
pub trait Control: BaseControl + Deref<Target = Widget> + DerefMut {
fn query_component(&self, type_id: TypeId) -> Option<&dyn Any>;
fn handle_routed_message(
&mut self,
ui: &mut UserInterface,
message: &mut UiMessage
);
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
fn query_component(&self, type_id: TypeId) -> Option<&dyn Any>
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>
.
fn handle_routed_message(
&mut self,
ui: &mut UserInterface,
message: &mut UiMessage
)
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
fn resolve(&mut self, _node_map: &NodeHandleMapping)
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 preview_message(&self, _ui: &UserInterface, _message: &mut UiMessage)
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.
fn handle_os_event(
&mut self,
_self_handle: Handle<UiNode>,
_ui: &mut UserInterface,
_event: &OsEvent
)
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
!