Skip to main content

ListEvent

Struct ListEvent 

Source
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: ViewRedraw

Redraw request for the host view.

§captured: bool

Whether the interaction was captured.

§message: Option<Message>

Optional delegate message.

§activity: ListActivity

List interaction mode.

Implementations§

Source§

impl<Message> ListEvent<Message>

Source

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    }
Source

pub fn into_view_event(self) -> ViewEvent<Message>

Converts the list event into a generic view event.

Examples found in repository?
examples/uikit_root.rs (line 80)
72    fn handle_touch(
73        &mut self,
74        touch: TouchEvent,
75        registration: &ViewRegistration<'static, DemoViewId, 2>,
76        _env: &ViewEnvironment<'_, 'static>,
77    ) -> ViewEvent<DemoMessage> {
78        self.list
79            .handle_touch(touch, registration.children()[0].frame)
80            .into_view_event()
81    }

Trait Implementations§

Source§

impl<Message: Clone> Clone for ListEvent<Message>

Source§

fn clone(&self) -> ListEvent<Message>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Message: Debug> Debug for ListEvent<Message>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Message: PartialEq> PartialEq for ListEvent<Message>

Source§

fn eq(&self, other: &ListEvent<Message>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Message: Copy> Copy for ListEvent<Message>

Source§

impl<Message: Eq> Eq for ListEvent<Message>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.