pub struct ListEvent<Message> {
pub redraw: ViewRedraw,
pub captured: bool,
pub message: Option<Message>,
pub activity: ListActivity,
}Expand description
Result of a list interaction.
Fields§
§redraw: ViewRedrawRedraw request for the host view.
captured: boolWhether the interaction was captured.
message: Option<Message>Optional delegate message.
activity: ListActivityList interaction mode.
Implementations§
Source§impl<Message> ListEvent<Message>
impl<Message> ListEvent<Message>
Sourcepub const fn none() -> Self
pub const fn none() -> Self
Returns a no-op list event.
Examples found in repository?
src/list_view/interaction.rs (line 21)
12 pub fn handle_touch<'text>(
13 &mut self,
14 touch: TouchEvent,
15 viewport: Rectangle,
16 ) -> ListEvent<Delegate::Message>
17 where
18 Delegate: ListDelegate<'text, DataSource::ItemId>,
19 {
20 if !touch.within(viewport) && !self.scroll_view.is_dragging() {
21 return ListEvent::none();
22 }
23
24 let local_touch = offset_touch(touch, viewport.top_left);
25 let touched_index = self.item_index_at_point(touch.point, viewport);
26 let was_dragging = self.scroll_view.is_dragging();
27 let previous_highlight = self.highlighted_index;
28 let previous_selection = self.selected_index;
29 let mut activity = ListActivity::None;
30 let mut message = None;
31
32 let scrolled = match touch.phase {
33 TouchPhase::Start => {
34 self.touch_started_inside = touch.within(viewport);
35 self.tap_candidate = self.touch_started_inside;
36 self.scroll_view.begin_drag(local_touch);
37 message = message.or(
38 self.set_highlighted_index(touched_index.filter(|_| self.touch_started_inside))
39 );
40 false
41 }
42 TouchPhase::Move => {
43 let changed =
44 self.scroll_view
45 .drag(local_touch, self.content_height(), viewport.size.height);
46 if changed || self.scroll_view.is_scrolling() {
47 self.tap_candidate = false;
48 message = message.or(self.set_highlighted_index(None));
49 } else {
50 let next_highlight = if self.touch_started_inside && touch.within(viewport) {
51 touched_index
52 } else {
53 None
54 };
55 message = message.or(self.set_highlighted_index(next_highlight));
56 }
57 changed
58 }
59 TouchPhase::End | TouchPhase::Cancel => {
60 let changed = self.scroll_view.end_drag(
61 local_touch,
62 self.content_height(),
63 viewport.size.height,
64 );
65
66 if matches!(touch.phase, TouchPhase::End)
67 && self.touch_started_inside
68 && self.tap_candidate
69 && touch.within(viewport)
70 {
71 if let Some(index) = touched_index {
72 if self.allows_selection {
73 self.selected_index = Some(index);
74 }
75 if let Some(selection) = self.selection_for_index(index) {
76 message = message.or(self.delegate.did_select_item(selection));
77 }
78 }
79 }
80
81 message = message.or(self.set_highlighted_index(None));
82 self.touch_started_inside = false;
83 self.tap_candidate = false;
84 changed
85 }
86 };
87
88 let visual_state_changed = previous_highlight != self.highlighted_index
89 || previous_selection != self.selected_index;
90 let motion_active = scrolled || self.scroll_view.is_scrolling();
91
92 if motion_active {
93 activity = ListActivity::Motion;
94 } else if visual_state_changed {
95 activity = ListActivity::Interactive;
96 }
97
98 ListEvent {
99 redraw: match activity {
100 ListActivity::None => ViewRedraw::None,
101 ListActivity::Interactive | ListActivity::Motion => ViewRedraw::Dirty(viewport),
102 },
103 captured: was_dragging || touch.within(viewport) || self.touch_started_inside,
104 message,
105 activity,
106 }
107 }Sourcepub fn into_view_event(self) -> ViewEvent<Message>
pub fn into_view_event(self) -> ViewEvent<Message>
Converts the list event into a generic view event.
Trait Implementations§
impl<Message: Copy> Copy for ListEvent<Message>
impl<Message: Eq> Eq for ListEvent<Message>
impl<Message> StructuralPartialEq for ListEvent<Message>
Auto Trait Implementations§
impl<Message> Freeze for ListEvent<Message>where
Message: Freeze,
impl<Message> RefUnwindSafe for ListEvent<Message>where
Message: RefUnwindSafe,
impl<Message> Send for ListEvent<Message>where
Message: Send,
impl<Message> Sync for ListEvent<Message>where
Message: Sync,
impl<Message> Unpin for ListEvent<Message>where
Message: Unpin,
impl<Message> UnsafeUnpin for ListEvent<Message>where
Message: UnsafeUnpin,
impl<Message> UnwindSafe for ListEvent<Message>where
Message: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.