[−][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
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&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.
pub fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&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
pub fn set_rect(&mut self, rect: Rect, _align: AlignHints)
[src]
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.
pub fn translation(&self, _child_index: usize) -> Coord
[src]
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.
pub fn spatial_range(&self) -> (usize, usize)
[src]
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).
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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 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
pub fn size_rules(&mut self, _: &mut dyn SizeHandle, _: AxisInfo) -> SizeRules
[src]
pub fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
pub fn draw(&self, _: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl Layout for Filler
[src]
pub fn size_rules(&mut self, _: &mut dyn SizeHandle, _: AxisInfo) -> SizeRules
[src]
pub fn draw(&self, _: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl Layout for AccelLabel
[src]
pub fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
_: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
_: bool
)
impl Layout for StringLabel
[src]
pub fn draw(&self, draw_handle: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl<'a> Layout for Label<&'a str>
[src]
pub fn draw(&self, draw_handle: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl<D: Directional> Layout for ScrollBar<D>
[src]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn spatial_range(&self) -> (usize, usize)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn spatial_range(&self) -> (usize, usize)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn spatial_range(&self) -> (usize, usize)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn draw(&self, draw_handle: &mut dyn DrawHandle, _: &ManagerState, _: bool)
[src]
impl<T: FormattableText + 'static> Layout for Label<T>
[src]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub default fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
_: &ManagerState,
_: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
_: &ManagerState,
_: bool
)
impl<T: FormattableText + 'static> Layout for MessageBox<T>
[src]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
impl<T: SliderType, D: Directional> Layout for Slider<T, D>
[src]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, _: AlignHints)
[src]
pub fn translation(&self, child_index: usize) -> Coord
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub 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]
pub fn size_rules(
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
[src]
&mut self,
size_handle: &mut dyn SizeHandle,
axis: AxisInfo
) -> SizeRules
pub fn set_rect(&mut self, rect: Rect, align: AlignHints)
[src]
pub fn find_id(&self, coord: Coord) -> Option<WidgetId>
[src]
pub fn draw(
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)
[src]
&self,
draw_handle: &mut dyn DrawHandle,
mgr: &ManagerState,
disabled: bool
)