Skip to main content

ScrollState

Struct ScrollState 

Source
pub struct ScrollState {
    pub offset: [f32; 2],
    pub max_offset: [f32; 2],
}
Expand description

How far a scroll box is scrolled (Ui::scroll_state).

Fields§

§offset: [f32; 2]

How far it is scrolled: across and down, in units from its start.

§max_offset: [f32; 2]

How far it can scroll each way: to where its content’s end shows.

Implementations§

Source§

impl ScrollState

Source

pub fn at_end(&self) -> bool

Whether it shows its content’s vertical end (as one with no more content than it shows does).

Examples found in repository?
examples/chat.rs (line 78)
50pub fn describe(app: &mut Chat, ui: &mut Ui) {
51    let t = ui.theme;
52    // The friend's answer, once it is ready; until then, the interface is woken for it.
53    match app.answer_at {
54        Some(at) if at <= app.now => {
55            app.add(false, ANSWERS[app.answered % ANSWERS.len()].into());
56            (app.answer_at, app.answered) = (None, app.answered + 1);
57        }
58        Some(at) => ui.wake_after(at - app.now),
59        None => {}
60    }
61
62    // The list, and what lies over it (the friend writing, the way back to the newest).
63    ui.column().grow().open();
64    ui.el().grow().flow(Flow::Stack).open();
65    // (A few stand at the bottom, as the newest always does.)
66    let list = ui.column().key("list").grow().scroll().align(Align::End, Align::Spread).open();
67    ui.stick_to_bottom(&list);
68    if std::mem::take(&mut app.to_end) {
69        ui.scroll_to(&list, [f32::NAN, f32::INFINITY]);
70    }
71    // Each message as high as its text comes out: only the ones in view are described.
72    let wide = ui.size().w;
73    for at in ui.variable_rows(app.messages.len(), 40.0) {
74        bubble(&app.messages[at], wide, ui);
75    }
76    ui.close();
77    ui.close();
78    app.at_end = ui.scroll_state(&list).at_end();
79    app.unread = if app.at_end { 0 } else { app.unread };
80    if app.messages.is_empty() {
81        ui.row().place(Align::Center).open();
82        ui.text("No messages yet. Say hello!", t.font, t.text_faint);
83        ui.close();
84    }
85    if app.answer_at.is_some() {
86        ui.row().place((Align::Start, Align::End)).pad((14.0, 4.0)).open();
87        ui.note("Sam is writing\u{2026}");
88        ui.close();
89    }
90    if !app.at_end {
91        ui.row().place((Align::Center, Align::End)).pad(6.0).gap(8.0).fill(t.raised).radius(t.radius).align(Align::Center, Align::Center).open();
92        if app.unread > 0 {
93            ui.note(&format!("{} new", app.unread));
94        }
95        app.to_end |= ui.button("Back to the newest").clicked;
96        ui.close();
97    }
98    ui.close();
99
100    // The box to type in: Enter sends what is in it, as the button does; Shift and Enter
101    // start a new line.
102    ui.row().pad(10.0).gap(8.0).fill(t.panel).open();
103    ui.enter_submits();
104    let typing = ui.text_area(&mut app.typed, "Write a message", (1, 4));
105    let send = ui.primary_button("Send").clicked || typing.focused && ui.key(Key::Enter, Mods::NONE);
106    ui.close();
107    ui.close();
108    if send && !app.typed.trim().is_empty() {
109        let text = std::mem::take(&mut app.typed);
110        app.add(true, text.trim().into());
111        // (What one sends, one sees.)
112        (app.to_end, app.answer_at) = (true, Some(app.now + THINKING));
113    }
114}

Trait Implementations§

Source§

impl Clone for ScrollState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ScrollState

Source§

impl Debug for ScrollState

Source§

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

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

impl Default for ScrollState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ScrollState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ScrollState

Auto Trait Implementations§

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> 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<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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.