[−][src]Trait kas::Widget
A widget is a UI element.
Widgets usually occupy space within the UI and are drawable. Widgets may respond to user events. Widgets may have child widgets.
Widgets must implement the child trait WidgetCore
and the
Handler
trait, besides this trait.
It is recommended to use the derive(Widget)
macro to generate some of the
required implementations. See documentation in the kas::macros
module.
Example of a simple widget which draws a frame around its child:
use kas::macros::Widget; use kas::{CoreData, LayoutData, Widget}; #[widget] #[layout(single, frame)] #[derive(Clone, Debug, Widget)] pub struct Frame<W: Widget> { #[core] core: CoreData, #[layout_data] layout_data: <Self as LayoutData>::Data, #[widget] child: W, }
Provided methods
fn configure(&mut self, _: &mut Manager)
Configure widget
Widgets are configured on window creation and when
kas::TkAction::Reconfigure
is sent.
This method is called immediately after assigning self.core_data().id
.
fn update_timer(&mut self, _: &mut Manager) -> Option<Duration>
Update the widget via a timer
This method is called on scheduled updates (see update_on_timer
).
When some Duration
is returned, another timed update is scheduled
at approximately this duration from now (but without blocking redraws;
usage of 1ns effectively enables per-frame update with FPS limited via
VSync). Required: duration > 0
.
This method being called does not imply a redraw.
fn update_handle(&mut self, _: &mut Manager, _: UpdateHandle)
Update the widget via an update handle
This method is called on triggered updates (see update_on_handle
).
The source handle is specified via the UpdateHandle
parameter.
This method being called does not imply a redraw.
fn allow_focus(&self) -> bool
Is this widget navigable via Tab key?