Widget

Trait Widget 

Source
pub trait Widget: Tile {
    type Data;

    // Provided methods
    fn as_node<'a>(&'a mut self, data: &'a Self::Data) -> Node<'a> { ... }
    fn child_node<'n>(
        &'n mut self,
        data: &'n Self::Data,
        index: usize,
    ) -> Option<Node<'n>> { ... }
}
Expand description

The Widget trait

The primary widget trait covers event handling over super trait Tile which governs layout, drawing, child enumeration and identification. Most methods of Widget are hidden and only for use within the Kas library.

Widget is dyn-safe given a type parameter, e.g. dyn Widget<Data = ()>. Tile is dyn-safe without a type parameter. Node is a dyn-safe abstraction over a &dyn Widget<Data = T> plus a &T data parameter.

§Widget lifecycle

  1. The widget is configured (Events::configure) and immediately updated (Events::update).
  2. The widget has its size-requirements checked by calling Layout::size_rules for each axis.
  3. Layout::set_rect is called to position elements. This may use data cached by size_rules.
  4. The widget is updated again after any data change (see ConfigCx::update).
  5. The widget is ready for event-handling and drawing (Events::handle_event, Layout::try_probe, Layout::draw).

Widgets are responsible for ensuring that their children may observe this lifecycle. Usually this simply involves inclusion of the child in layout operations. Steps of the lifecycle may be postponed until a widget becomes visible.

§Implementing Widget

To implement a widget, use the #widget macro within an impl_self, impl_scope! or impl_anon! macro. This is the only supported method of implementing Widget.

Explicit (partial) implementations of Widget, Layout, Tile and Events are optional. The #widget macro completes implementations.

Synopsis:

#[impl_self]
mod MyWidget {
    #[widget {
        // macro properties (all optional)
        Data = T;
    }]
    #[layout(self.foo)]
    struct MyWidget {
        core: widget_core!(),
        #[widget] foo: impl Widget<Data = T> = make_foo(),
        // ...
    }

    // Optional implementations:
    impl Layout for Self { /* ... */ }
    impl Events for Self { /* ... */ }
    impl Self { /* ... */ }
}

Details may be categorised as follows:

For examples, check the source code of widgets in the widgets library or examples apps. (Check that the code uses the same Kas version since the widget traits are not yet stable.)

Required Associated Types§

Source

type Data

Input data type

Widget expects data of this type to be provided by reference when calling any event-handling operation on this widget.

Type Data should be specified either here (impl Widget { ... }) or in impl Events { ... }. Alternatively, if the widget has no children and no explicit impl Events or impl Widget, then Data = () is assumed; or, if the prior conditions are met and #[collection] is used on some field, then Data = <#field_ty as ::kas::Collection>::Data is assumed.

Provided Methods§

Source

fn as_node<'a>(&'a mut self, data: &'a Self::Data) -> Node<'a>

Erase type

This method is implemented by the #[widget] macro.

Source

fn child_node<'n>( &'n mut self, data: &'n Self::Data, index: usize, ) -> Option<Node<'n>>

Access a child as a Node, if available

This method is the mut version of Tile::get_child but which also pairs the returned widget with its input data. It is expected to succeed where Tile::get_child succeeds.

Valid index values may be discovered by calling Tile::child_indices, Tile::find_child_index or Tile::nav_next. The index-to-child mapping is not required to remain fixed; use an Id to track a widget over time.

This method must be implemented explicitly when Tile::get_child is. It might also need to be implemented explicitly to map data, though usually the #[widget] attribute on children specifies this mapping.

Implementations on Foreign Types§

Source§

impl<T> Widget for &mut T
where T: Widget + ?Sized,

Source§

type Data = <T as Widget>::Data

Source§

fn as_node<'a>(&'a mut self, data: &'a <&mut T as Widget>::Data) -> Node<'a>

Source§

fn child_node<'n>( &'n mut self, data: &'n <&mut T as Widget>::Data, index: usize, ) -> Option<Node<'n>>

Source§

impl<T> Widget for Box<T>
where T: Widget + ?Sized,

Source§

type Data = <T as Widget>::Data

Source§

fn as_node<'a>(&'a mut self, data: &'a <Box<T> as Widget>::Data) -> Node<'a>

Source§

fn child_node<'n>( &'n mut self, data: &'n <Box<T> as Widget>::Data, index: usize, ) -> Option<Node<'n>>

Implementors§

Source§

impl Widget for Svg

Source§

impl Widget for TextEdit

Source§

impl Widget for AccessLabel

Source§

impl Widget for EventConfig

Source§

impl Widget for Filler

Source§

impl Widget for GripPart

Source§

impl Widget for Image

Source§

impl Widget for Mark

Source§

impl Widget for Tab

Source§

impl Widget for TitleBar

Source§

impl Widget for TitleBarButtons

Source§

impl<A> Widget for MenuToggle<A>

Source§

type Data = A

Source§

impl<A> Widget for CheckBox<A>

Source§

type Data = A

Source§

impl<A> Widget for CheckButton<A>

Source§

type Data = A

Source§

impl<A> Widget for Page<A>

Source§

type Data = A

Source§

impl<A> Widget for RadioBox<A>

Source§

type Data = A

Source§

impl<A> Widget for RadioButton<A>

Source§

type Data = A

Source§

impl<A> Widget for Separator<A>

Source§

type Data = A

Source§

impl<A> Widget for Stack<A>

Source§

type Data = A

Source§

impl<A> Widget for TabStack<A>

Source§

type Data = A

Source§

impl<A, D> Widget for ProgressBar<A, D>
where D: Directional,

Source§

type Data = A

Source§

impl<A, T> Widget for ScrollText<A, T>
where T: FormattableText + 'static,

Source§

type Data = A

Source§

impl<A, T> Widget for SelectableText<A, T>
where T: FormattableText + 'static,

Source§

type Data = A

Source§

impl<A, T> Widget for SpinBox<A, T>
where T: SpinValue,

Source§

type Data = A

Source§

impl<A, T> Widget for Text<A, T>
where T: Default + FormattableText + 'static,

Source§

type Data = A

Source§

impl<A, T, D> Widget for Slider<A, T, D>
where T: SliderValue, D: Directional,

Source§

type Data = A

Source§

impl<A, V> Widget for ComboBox<A, V>
where V: Clone + Debug + Eq + 'static,

Source§

type Data = A

Source§

impl<A, W> Widget for MapAny<A, W>
where W: Widget<Data = ()>,

Source§

type Data = A

Source§

impl<A, W> Widget for Adapt<A, W>
where W: Widget,

Source§

type Data = A

Source§

impl<A, W, F> Widget for Map<A, W, F>
where W: Widget, F: for<'a> Fn(&'a A) -> &'a <W as Widget>::Data,

Source§

type Data = A

Source§

impl<C> Widget for Float<C>
where C: Collection,

Source§

impl<C> Widget for Grid<C>
where C: CellCollection,

Source§

impl<C, D> Widget for List<C, D>
where C: Collection, D: Directional,

Source§

impl<C, D> Widget for Splitter<C, D>
where C: Collection, D: Directional,

Source§

impl<C, V> Widget for GridView<C, V>

Source§

impl<C, V, D> Widget for ListView<C, V, D>
where C: DataClerk<usize>, V: Driver<<C as DataClerk<usize>>::Key, <C as DataClerk<usize>>::Item>, D: Directional,

Source§

impl<D> Widget for ScrollBar<D>
where D: Directional,

Source§

impl<Data> Widget for Window<Data>
where Data: AppData,

Source§

type Data = Data

Source§

impl<Data, D> Widget for MenuBar<Data, D>
where D: Directional,

Source§

type Data = Data

Source§

impl<F, A, V, G, D> Widget for FilterBoxListView<F, A, V, G, D>
where F: Filter<<A as DataClerk<usize>>::Item, Value = String>, A: DataClerk<usize, Data = F>, V: Driver<<A as DataClerk<usize>>::Key, <A as DataClerk<usize>>::Item>, G: EditGuard<Data = ()>, D: Directional,

Source§

impl<G> Widget for EditBox<G>
where G: EditGuard,

Source§

type Data = <G as EditGuard>::Data

Source§

impl<G> Widget for EditField<G>
where G: EditGuard,

Source§

type Data = <G as EditGuard>::Data

Source§

impl<M> Widget for MenuEntry<M>
where M: Clone + Debug + 'static,

Source§

impl<M> Widget for MarkButton<M>
where M: Clone + Debug + 'static,

Source§

impl<P> Widget for Canvas<P>
where P: CanvasProgram,

Source§

impl<T> Widget for AlertError<T>
where T: FormattableText + 'static,

Source§

impl<T> Widget for AlertUnsaved<T>
where T: FormattableText + 'static,

Source§

impl<T> Widget for MessageBox<T>
where T: FormattableText + 'static,

Source§

impl<T> Widget for Label<T>
where T: FormattableText + 'static,

Source§

impl<W> Widget for AdaptEvents<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Align<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Margins<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Pack<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Reserve<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for WithHiddenLabel<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Button<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Frame<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for ScrollBarRegion<W>
where W: Widget,

Source§

impl<W> Widget for ScrollBars<W>
where W: Scrollable + Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for ScrollRegion<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W> Widget for Popup<W>
where W: Widget,

Source§

type Data = <W as Widget>::Data

Source§

impl<W, D> Widget for WithLabel<W, D>
where W: Widget, D: Directional,

Source§

type Data = <W as Widget>::Data

Source§

impl<const TOP_LEVEL: bool, Data> Widget for SubMenu<TOP_LEVEL, Data>

Source§

type Data = Data