[−][src]Trait kas::Layout
Positioning and drawing routines for widgets
This trait is part of the Widget
family. It may be derived by
derive(Widget)
, but is not by default.
This trait contains methods concerned with positioning of contents as well as low-level event handling.
For parent widgets, the implementation will often be derived (see
kas::macros
); otherwise, a layout engine may be used (see
kas::layout
). For leaf widgets, it is implemented directly.
For a description of the widget size model, see SizeRules
.
Required methods
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
&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.
Fields written by set_rect
should not be used for this cache since
set_rect
may be called multiple times without re-calling size_rules
.
To allow automatic flow of content over new lines, the width is sized
first, followed by the height; when sizing for height, AxisInfo
contains the size of the other axis (i.e. the width).
For widgets with children, a kas::layout::RulesSolver
engine may be
useful to calculate requirements of complex layouts.
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
Draw a widget and its children
This method is invoked each frame to draw visible widgets. It should draw itself and recurse into all visible children.
The disabled
argument is passed in from the parent; a widget should
use let disabled = disabled || self.is_disabled();
to determine its
own disabled state, then pass this value on to children.
WidgetCore::input_state
may be used to obtain an InputState
to
determine active visual effects.
Provided methods
fn set_rect(&mut self, rect: Rect, _align: AlignHints)
Apply a given rect
to self
For widgets without children, the trivial default implementation of this method often suffices, though some widgets choose to align themselves within this space. Alignment may be applied in one of two ways:
- Shrinking to ideal area and aligning within available space (e.g.
CheckBoxBare
widget) - Filling available space and applying alignment to contents (e.g.
Label
widget)
For widgets with children, a kas::layout::RulesSetter
engine may be
useful (used with a corresponding kas::layout::RulesSolver
).
One may assume that size_rules
has been called at least once for each
axis with current size information before this method, however
size_rules
might not be re-called before calling set_rect
again.
fn translation(&self, _child_index: usize) -> Coord
Get translation of a child
Children may live in a translated coordinate space relative to their parent. This method returns an offset which should be added to a coordinate to translate into the child's coordinate space or subtracted to translate out.
In most cases, the translation will be zero. Widgets should return
Coord::ZERO
for non-existant children.
fn spatial_range(&self) -> (usize, usize)
Iterate through children in spatial order
Returns a "range" of children, by index, in spatial order. Unlike
std::ops::Range
this is inclusive and reversible, e.g. (1, 3)
means
1, 2, 3
and (5, 2)
means 5, 4, 3, 2
. As a special case,
(_, std::usize::MAX)
means the range is empty.
Widgets should return a range over children in spatial order (left-to-right then top-to-bottom). Widgets outside the parent's rect (i.e. popups) should be excluded.
The default implementation should suffice for most widgets (excluding pop-up parents and those with reversed child order).
fn find_id(&self, coord: Coord) -> Option<WidgetId>
Find a widget by coordinate
Returns the identifier of the widget containing this coord
, if any.
Should only return None
when coord
is outside the widget's rect,
but this is not guaranteed.
Implementations should:
- return
None
if!self.rect().contains(coord)
- if, for any child (containing
coord
),child.find_id(coord)
returnsSome(id)
, return that - otherwise, return
Some(self.id())
Exceptionally, a widget may deviate from this behaviour, but only when
the coord is within the widget's rect (example: CheckBox
contains an
embedded CheckBoxBare
and always forwards this child's id).
This must not be called before Layout::set_rect
.
Implementations on Foreign Types
impl<M: 'static> Layout for Box<dyn Widget<Msg = M>>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for Box<dyn Menu<Msg = M>>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
Implementors
impl Layout for AccelLabel
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn draw(&self, draw_handle: &mut dyn DrawHandle, mgr: &ManagerState, _: bool)
[src]
impl Layout for DragHandle
[src]
This implementation is unusual in that:
size_rules
always returnsSizeRules::EMPTY
set_rect
sets the track within which this handle may move; the parent should callDragHandle::set_size_and_offset
afterset_rect
(otherwise the handle's offset will not be updated)draw
does nothing: the parent is expected to do all drawing
fn size_rules(&mut self, _: &mut dyn SizeHandle, _: AxisInfo) -> SizeRules
[src]
fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
fn draw(&self, _: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl Layout for Filler
[src]
fn size_rules(&mut self, _: &mut dyn SizeHandle, _: AxisInfo) -> SizeRules
[src]
fn draw(&self, _: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl Layout for Label
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn draw(&self, draw_handle: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl Layout for MessageBox
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<D: Directional> Layout for ScrollBar<D>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<D: Directional, W: Widget> Layout for List<D, W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn spatial_range(&self) -> (usize, usize)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<D: Directional, W: Widget> Layout for Splitter<D, W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<D: Directional, W: Menu> Layout for MenuBar<D, W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<D: Directional, W: Menu> Layout for SubMenu<D, W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn spatial_range(&self) -> (usize, usize)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<G: 'static> Layout for EditBox<G>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for CheckBox<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for CheckBoxBare<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for MenuToggle<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for RadioBox<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: 'static> Layout for RadioBoxBare<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: Clone + Debug + 'static> Layout for ComboBox<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, _align: AlignHints)
[src]
fn spatial_range(&self) -> (usize, usize)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: Clone + Debug + 'static> Layout for MenuEntry<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: Clone + Debug + 'static> Layout for TextButton<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, _align: AlignHints)
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<M: Debug> Layout for Separator<M>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn draw(&self, draw_handle: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl<T: SliderType, D: Directional> Layout for Slider<T, D>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<W: Widget> Layout for Frame<W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<W: Widget> Layout for MenuFrame<W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<W: Widget> Layout for ScrollRegion<W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
fn translation(&self, child_index: usize) -> Coord
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<W: Widget> Layout for Stack<W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<W: Widget> Layout for Window<W>
[src]
fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)