Struct kas::view::MatrixView
source · pub struct MatrixView<A, V>{ /* private fields */ }
view
only.Expand description
View controller for 2D indexable data (matrix)
This widget generates a view over a list of data items via the
MatrixData
trait. “View widgets” are constructed via a Driver
to
represent visible data items. These view widgets are reassigned as
required when the matrix is scrolled, keeping the number of widgets in
use roughly proportional to the number of data items within the view.
Each view widget has an Id
corresponding to its current data
item, and may handle events and emit messages like other widegts.
See Driver
documentation for more on event handling.
This widget is Scrollable
, supporting keyboard, wheel and drag
scrolling. You may wish to wrap this widget with ScrollBars
.
Optionally, data items may be selected; see Self::set_selection_mode
.
If enabled, SelectionMsg
messages are reported; view widgets may
emit kas::messages::Select
to have themselves be selected.
Implementations§
source§impl<A, V> MatrixView<A, V>
impl<A, V> MatrixView<A, V>
sourcepub fn new(driver: V) -> MatrixView<A, V>
pub fn new(driver: V) -> MatrixView<A, V>
Construct a new instance
sourcepub fn selection_mode(&self) -> SelectionMode
pub fn selection_mode(&self) -> SelectionMode
Get the current selection mode
sourcepub fn set_selection_mode(&mut self, mode: SelectionMode) -> Action
pub fn set_selection_mode(&mut self, mode: SelectionMode) -> Action
Set the current selection mode
By default, selection is disabled. If enabled, items may be selected
and deselected via mouse-click/touch or via a view widget emitting
Select
.
On selection and deselection, a SelectionMsg
message is emitted.
This is not sent to Driver::on_messages
.
The driver may trigger selection by emitting Select
from
Driver::on_messages
. The driver is not notified of selection
except via Select
from view widgets. (TODO: reconsider this.)
sourcepub fn with_selection_mode(self, mode: SelectionMode) -> MatrixView<A, V>
pub fn with_selection_mode(self, mode: SelectionMode) -> MatrixView<A, V>
Set the selection mode (inline)
See Self::set_selection_mode
documentation.
sourcepub fn selection_style(&self) -> SelectionStyle
pub fn selection_style(&self) -> SelectionStyle
Get the current selection style
sourcepub fn set_selection_style(&mut self, style: SelectionStyle) -> Action
pub fn set_selection_style(&mut self, style: SelectionStyle) -> Action
Set the current selection style
By default, SelectionStyle::Highlight
is used. Other modes may
add margin between elements.
sourcepub fn with_selection_style(self, style: SelectionStyle) -> MatrixView<A, V>
pub fn with_selection_style(self, style: SelectionStyle) -> MatrixView<A, V>
Set the selection style (inline)
See Self::set_selection_style
documentation.
sourcepub fn selected_iter(&self) -> impl Iterator<Item = &<A as SharedData>::Key>
pub fn selected_iter(&self) -> impl Iterator<Item = &<A as SharedData>::Key>
Read the list of selected entries
With mode SelectionMode::Single
this may contain zero or one entry;
use selected_iter().next()
to extract only the first (optional) entry.
sourcepub fn is_selected(&self, key: &<A as SharedData>::Key) -> bool
pub fn is_selected(&self, key: &<A as SharedData>::Key) -> bool
Check whether an entry is selected
sourcepub fn clear_selected(&mut self) -> Action
pub fn clear_selected(&mut self) -> Action
Clear all selected items
sourcepub fn select(&mut self, key: <A as SharedData>::Key) -> Action
pub fn select(&mut self, key: <A as SharedData>::Key) -> Action
Directly select an item
Does nothing if Self::selection_mode
is SelectionMode::None
.
Does not verify the validity of key
.
Does not send SelectionMsg
messages.
Returns Action::REDRAW
if newly selected, Action::empty()
if
already selected. Fails if selection mode does not permit selection
or if the key is invalid.
sourcepub fn deselect(&mut self, key: &<A as SharedData>::Key) -> Action
pub fn deselect(&mut self, key: &<A as SharedData>::Key) -> Action
Directly deselect an item
Returns Action::REDRAW
if deselected, Action::empty()
if not
previously selected or if the key is invalid.
sourcepub fn with_num_visible(self, cols: i32, rows: i32) -> MatrixView<A, V>
pub fn with_num_visible(self, cols: i32, rows: i32) -> MatrixView<A, V>
Set the preferred number of items visible (inline)
This affects the (ideal) size request and whether children are sized according to their ideal or minimum size but not the minimum size.
Trait Implementations§
source§impl<A, V> Clone for MatrixView<A, V>where
A: Clone + MatrixData,
V: Clone + Driver<<A as SharedData>::Item, A>,
<A as SharedData>::Key: Clone,
<V as Driver<<A as SharedData>::Item, A>>::Widget: Clone,
impl<A, V> Clone for MatrixView<A, V>where
A: Clone + MatrixData,
V: Clone + Driver<<A as SharedData>::Item, A>,
<A as SharedData>::Key: Clone,
<V as Driver<<A as SharedData>::Item, A>>::Widget: Clone,
source§fn clone(&self) -> MatrixView<A, V>
fn clone(&self) -> MatrixView<A, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<A, V> Debug for MatrixView<A, V>where
A: Debug + MatrixData,
V: Debug + Driver<<A as SharedData>::Item, A>,
<A as SharedData>::Key: Debug,
<V as Driver<<A as SharedData>::Item, A>>::Widget: Debug,
impl<A, V> Debug for MatrixView<A, V>where
A: Debug + MatrixData,
V: Debug + Driver<<A as SharedData>::Item, A>,
<A as SharedData>::Key: Debug,
<V as Driver<<A as SharedData>::Item, A>>::Widget: Debug,
source§impl<A, V> Events for MatrixView<A, V>
impl<A, V> Events for MatrixView<A, V>
source§fn configure_recurse(
&mut self,
_: &mut ConfigCx<'_>,
_: &<MatrixView<A, V> as Widget>::Data
)
fn configure_recurse( &mut self, _: &mut ConfigCx<'_>, _: &<MatrixView<A, V> as Widget>::Data )
source§fn update_recurse(
&mut self,
_: &mut ConfigCx<'_>,
_: &<MatrixView<A, V> as Widget>::Data
)
fn update_recurse( &mut self, _: &mut ConfigCx<'_>, _: &<MatrixView<A, V> as Widget>::Data )
source§fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &A)
fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &A)
source§fn handle_scroll(&mut self, cx: &mut EventCx<'_>, data: &A, scroll: Scroll)
fn handle_scroll(&mut self, cx: &mut EventCx<'_>, data: &A, scroll: Scroll)
source§fn steal_event(
&mut self,
_: &mut EventCx<'_>,
_: &<MatrixView<A, V> as Widget>::Data,
_: &Id,
_: &Event
) -> IsUsed
fn steal_event( &mut self, _: &mut EventCx<'_>, _: &<MatrixView<A, V> as Widget>::Data, _: &Id, _: &Event ) -> IsUsed
source§impl<A, V> Layout for MatrixView<A, V>
impl<A, V> Layout for MatrixView<A, V>
source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
source§fn get_child(&self, index: usize) -> Option<&dyn Layout>
fn get_child(&self, index: usize) -> Option<&dyn Layout>
dyn Layout
Read moresource§fn find_child_index(&self, id: &Id) -> Option<usize>
fn find_child_index(&self, id: &Id) -> Option<usize>
id
, if any Read moresource§fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
source§fn translation(&self) -> Offset
fn translation(&self) -> Offset
source§fn widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
source§impl<A, V> Scrollable for MatrixView<A, V>
impl<A, V> Scrollable for MatrixView<A, V>
Auto Trait Implementations§
impl<A, V> RefUnwindSafe for MatrixView<A, V>where
V: RefUnwindSafe,
<A as SharedData>::Key: RefUnwindSafe,
<V as Driver<<A as SharedData>::Item, A>>::Widget: RefUnwindSafe,
impl<A, V> !Send for MatrixView<A, V>
impl<A, V> !Sync for MatrixView<A, V>
impl<A, V> Unpin for MatrixView<A, V>where
V: Unpin,
<A as SharedData>::Key: Unpin,
<V as Driver<<A as SharedData>::Item, A>>::Widget: Unpin,
impl<A, V> UnwindSafe for MatrixView<A, V>where
V: UnwindSafe,
<A as SharedData>::Key: UnwindSafe,
<V as Driver<<A as SharedData>::Item, A>>::Widget: UnwindSafe,
Blanket Implementations§
source§impl<W> AdaptWidget for Wwhere
W: Widget,
impl<W> AdaptWidget for Wwhere
W: Widget,
source§fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
Events::configure
Read moresource§fn on_update<F>(self, f: F) -> AdaptEvents<Self>
fn on_update<F>(self, f: F) -> AdaptEvents<Self>
Events::update
Read moresource§fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
M
Read moresource§fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
source§fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
source§fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
source§fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
source§impl<W> AdaptWidgetAny for W
impl<W> AdaptWidgetAny for W
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<W> LayoutExt for W
impl<W> LayoutExt for W
source§fn identify(&self) -> IdentifyWidget<'_>
fn identify(&self) -> IdentifyWidget<'_>
source§fn is_strict_ancestor_of(&self, id: &Id) -> bool
fn is_strict_ancestor_of(&self, id: &Id) -> bool
id
is not self and is a descendant Read more