[−][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 additionally implement the traits WidgetCore
, Layout
and Handler
. The
derive(Widget)
macro may be
used to generate some of these implementations.
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,
_mgr: &mut Manager,
_handle: UpdateHandle,
_payload: u64
)
&mut self,
_mgr: &mut Manager,
_handle: UpdateHandle,
_payload: u64
)
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.
A user-defined payload is passed. Interpretation of this payload is user-defined and unfortunately not type safe.
This method being called does not imply a redraw.
fn allow_focus(&self) -> bool
Is this widget navigable via Tab key?
fn cursor_icon(&self) -> CursorIcon
Which cursor icon should be used on hover?
Where no specific icon should be used, return CursorIcon::Default
.
Implementations on Foreign Types
impl<M> Widget for Box<dyn Handler<Msg = M>>
[src]
fn configure(&mut self, mgr: &mut Manager)
[src]
fn update_timer(&mut self, mgr: &mut Manager) -> Option<Duration>
[src]
fn update_handle(
&mut self,
mgr: &mut Manager,
handle: UpdateHandle,
payload: u64
)
[src]
&mut self,
mgr: &mut Manager,
handle: UpdateHandle,
payload: u64
)