[][src]Trait kas::Layout

pub trait Layout: WidgetCore {
    fn size_rules(
        &mut self,
        size_handle: &mut dyn SizeHandle,
        axis: AxisInfo
    ) -> SizeRules;
fn draw(&self, draw_handle: &mut dyn DrawHandle, mgr: &ManagerState); fn set_rect(
        &mut self,
        _size_handle: &mut dyn SizeHandle,
        rect: Rect,
        _align: AlignHints
    ) { ... }
fn find_id(&self, _coord: Coord) -> Option<WidgetId> { ... } }

Positioning and drawing routines for widgets

This trait contains methods concerned with positioning of contents, other than those in kas::event::Handler.

Required methods

fn size_rules(
    &mut self,
    size_handle: &mut dyn SizeHandle,
    axis: AxisInfo
) -> SizeRules

Get size rules for the given axis.

This method takes &mut self to allow local caching of child widget configuration for future size_rules and set_rect calls.

Optionally, this method may set self.rect().size to the widget's ideal size for use by Layout::set_rect when setting alignment.

If operating on one axis and the other is fixed, then the other parameter is used for the fixed dimension. Additionally, one may assume that size_rules has previously been called on the fixed axis with the current widget configuration.

fn draw(&self, draw_handle: &mut dyn DrawHandle, mgr: &ManagerState)

Draw a widget

This method is called to draw each visible widget (and should not attempt recursion on child widgets).

Loading content...

Provided methods

fn set_rect(
    &mut self,
    _size_handle: &mut dyn SizeHandle,
    rect: Rect,
    _align: AlignHints
)

Adjust to the given size.

For widgets with children, this is usually implemented via the derive macro. For non-parent widgets which stretch to fill available space, the default implementation suffices. For non-parent widgets which react to alignment, this is a little more complex to implement, and can be done in one of two ways:

  1. Shrinking to ideal area and aligning within available space (e.g. CheckBoxBare widget)
  2. Filling available space and applying alignment to contents (e.g. Label widget)

One may assume that size_rules has been called for each axis with the current widget configuration.

fn find_id(&self, _coord: Coord) -> Option<WidgetId>

Find a child widget by coordinate

This is used by the event manager to target the correct widget given an event from a coordinate source (mouse pointer, touch event). Widgets may return their own Id over that of children in order to steal events (e.g. a button using an inner label widget).

This must not be called before Layout::set_rect.

In the case of an empty grid cell, the parent widget is returned (same behaviour as with events addressed by coordinate). The only case None should be expected is when coord is outside the initial widget's region; however this is not guaranteed.

Loading content...

Implementations on Foreign Types

impl<M> Layout for Box<dyn Handler<Msg = M>>[src]

Loading content...

Implementors

impl Layout for Filler[src]

impl Layout for Label[src]

impl Layout for MessageBox[src]

impl<D: Directional> Layout for ScrollBar<D>[src]

impl<D: Directional, W: Widget> Layout for List<D, W>[src]

impl<H: 'static> Layout for EditBox<H>[src]

impl<M: Clone + Debug> Layout for TextButton<M>[src]

impl<OT: 'static> Layout for CheckBox<OT>[src]

impl<OT: 'static> Layout for CheckBoxBare<OT>[src]

impl<OT: 'static> Layout for RadioBox<OT>[src]

impl<OT: 'static> Layout for RadioBoxBare<OT>[src]

impl<W: Widget + 'static> Layout for Window<W>[src]

impl<W: Widget> Layout for ScrollRegion<W>[src]

Loading content...