Trait kas::Widget[][src]

pub trait Widget: SendEvent { }
Expand description

Widget trait

Widgets must implement a family of traits, of which this trait is the final member:

  • WidgetCore — base functionality (this trait is always derived)
  • WidgetChildren — enumerates children and provides methods derived from this
  • Layout — handles sizing and positioning of self and children
  • WidgetConfig — the last unparametrised trait allows customisation of some aspects of widget behaviour
  • event::Handler — parametrised widgets over a Msg type and handles events
  • event::SendEvent — routes events to children and handles responses
  • Widget — the final trait

Widgets must use the derive(Widget) macro to implement at least WidgetCore and Widget; these two traits must not be implemented manually or users may face unexpected breaking changes. This macro can optionally implement all above traits, and by default will implement all except for Layout. This opt-out derive behaviour means that adding additional traits into the family is not a breaking change.

To refer to a widget via dyn trait, use &dyn WidgetConfig (or, if the message type is known, one may use &dyn Widget<Msg = M>). To refer to a widget in generic functions, use <W: Widget> or <M, W: Widget<Msg = M>>.

Trait Implementations

Boxing method

Implementations on Foreign Types

Implementors