pub struct GridView<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> { /* private fields */ }
Expand description
View controller for 2D indexable data (grid)
This widget generates a view over a list of data items via a
DataClerk
. “View widgets” are constructed via a Driver
to represent visible data items. These view widgets are reassigned as
required when the grid 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.
§Messages
kas::messages::SetScrollOffset
may be used to set the scroll offset.
Implementations§
Source§impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> GridView<C, V>
impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> GridView<C, V>
Sourcepub fn clerk_mut(&mut self) -> &mut C
pub fn clerk_mut(&mut self) -> &mut C
Access the data clerk (mutably)
Changes to the clerk must be notified with an update to the
GridView
, for example using ConfigCx::update
,
EventCx::update
or Action::UPDATE
.
Sourcepub fn view_range(&self) -> Range<GridIndex>
pub fn view_range(&self) -> Range<GridIndex>
Get the range of visible data items
Data items within this range may be visible (or should at least be allocated some pixel within the controller’s view).
Sourcepub fn selection_mode(&self) -> SelectionMode
pub fn selection_mode(&self) -> SelectionMode
Get the current selection mode
Sourcepub fn set_selection_mode(&mut self, cx: &mut EventState, mode: SelectionMode)
pub fn set_selection_mode(&mut self, cx: &mut EventState, mode: SelectionMode)
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.
Sourcepub fn with_selection_mode(self, mode: SelectionMode) -> Self
pub fn with_selection_mode(self, mode: SelectionMode) -> Self
Set the initial 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,
cx: &mut EventState,
style: SelectionStyle,
)
pub fn set_selection_style( &mut self, cx: &mut EventState, style: SelectionStyle, )
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) -> Self
pub fn with_selection_style(self, style: SelectionStyle) -> Self
Set the selection style (inline)
See Self::set_selection_style
documentation.
Sourcepub fn selected_iter(&self) -> impl Iterator<Item = &C::Key> + '_
pub fn selected_iter(&self) -> impl Iterator<Item = &C::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: &C::Key) -> bool
pub fn is_selected(&self, key: &C::Key) -> bool
Check whether an entry is selected
Sourcepub fn clear_selected(&mut self, cx: &mut EventState)
pub fn clear_selected(&mut self, cx: &mut EventState)
Clear all selected items
Sourcepub fn select(&mut self, cx: &mut EventState, key: C::Key) -> bool
pub fn select(&mut self, cx: &mut EventState, key: C::Key) -> bool
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 true
if newly selected, false
if
already selected. Fails if selection mode does not permit selection
or if the key is invalid.
Sourcepub fn deselect(&mut self, cx: &mut EventState, key: &C::Key) -> bool
pub fn deselect(&mut self, cx: &mut EventState, key: &C::Key) -> bool
Directly deselect an item
Returns true
if deselected, false
if not
previously selected or if the key is invalid.
Sourcepub fn with_num_visible(self, cols: u32, rows: u32) -> Self
pub fn with_num_visible(self, cols: u32, rows: u32) -> Self
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<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Events for GridView<C, V>
impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Events for GridView<C, V>
Source§fn mouse_over_icon(&self) -> Option<CursorIcon>
fn mouse_over_icon(&self) -> Option<CursorIcon>
Source§fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
Source§fn update(&mut self, cx: &mut ConfigCx<'_>, data: &C::Data)
fn update(&mut self, cx: &mut ConfigCx<'_>, data: &C::Data)
Source§fn handle_event(
&mut self,
cx: &mut EventCx<'_>,
data: &C::Data,
event: Event<'_>,
) -> IsUsed
fn handle_event( &mut self, cx: &mut EventCx<'_>, data: &C::Data, event: Event<'_>, ) -> IsUsed
Source§fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &C::Data)
fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &C::Data)
Source§fn handle_scroll(
&mut self,
cx: &mut EventCx<'_>,
data: &C::Data,
scroll: Scroll,
)
fn handle_scroll( &mut self, cx: &mut EventCx<'_>, data: &C::Data, scroll: Scroll, )
Source§const REDRAW_ON_MOUSE_OVER: bool = false
const REDRAW_ON_MOUSE_OVER: bool = false
Source§impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Layout for GridView<C, V>
impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Layout for GridView<C, V>
Source§impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Scrollable for GridView<C, V>
impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Scrollable for GridView<C, V>
Source§fn content_size(&self) -> Size
fn content_size(&self) -> Size
Source§fn max_scroll_offset(&self) -> Offset
fn max_scroll_offset(&self) -> Offset
Source§fn scroll_offset(&self) -> Offset
fn scroll_offset(&self) -> Offset
Source§impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Tile for GridView<C, V>
impl<C: DataClerk<GridIndex>, V: Driver<C::Key, C::Item>> Tile for GridView<C, V>
Source§fn child_indices(&self) -> ChildIndices
fn child_indices(&self) -> ChildIndices
Source§fn get_child(&self, index: usize) -> Option<&dyn Tile>
fn get_child(&self, index: usize) -> Option<&dyn Tile>
dyn Tile
, if available 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 translation(&self, _: usize) -> Offset
fn translation(&self, _: usize) -> Offset
index
relative to this widget Read moreAuto Trait Implementations§
impl<C, V> Freeze for GridView<C, V>
impl<C, V> RefUnwindSafe for GridView<C, V>where
C: RefUnwindSafe,
V: RefUnwindSafe,
<C as DataClerk<GridIndex>>::Key: RefUnwindSafe,
<C as DataClerk<GridIndex>>::Token: RefUnwindSafe,
<V as Driver<<C as DataClerk<GridIndex>>::Key, <C as DataClerk<GridIndex>>::Item>>::Widget: RefUnwindSafe,
impl<C, V> !Send for GridView<C, V>
impl<C, V> !Sync for GridView<C, V>
impl<C, V> Unpin for GridView<C, V>
impl<C, V> UnwindSafe for GridView<C, V>where
C: UnwindSafe,
V: UnwindSafe,
<C as DataClerk<GridIndex>>::Key: UnwindSafe,
<C as DataClerk<GridIndex>>::Token: UnwindSafe,
<V as Driver<<C as DataClerk<GridIndex>>::Key, <C as DataClerk<GridIndex>>::Item>>::Widget: UnwindSafe,
Blanket Implementations§
Source§impl<W> AdaptWidget for Wwhere
W: Widget,
impl<W> AdaptWidget for Wwhere
W: Widget,
Source§fn pack(self, hints: AlignHints) -> Pack<Self>
fn pack(self, hints: AlignHints) -> Pack<Self>
Source§fn margins(self, dirs: Directions, style: MarginStyle) -> Margins<Self>
fn margins(self, dirs: Directions, style: MarginStyle) -> Margins<Self>
Source§fn on_configure<F>(self, f: F) -> AdaptEvents<Self>where
F: Fn(&mut AdaptConfigCx<'_, '_>, &mut Self) + 'static,
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>where
F: Fn(&mut AdaptConfigCx<'_, '_>, &mut Self) + 'static,
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 map_message<M, N, H>(self, handler: H) -> AdaptEvents<Self>
fn map_message<M, N, H>(self, handler: H) -> AdaptEvents<Self>
Source§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
Source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<W> TileExt for W
impl<W> TileExt for W
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