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
impl ScrollState
Sourcepub fn at_end(&self) -> bool
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
impl Clone for ScrollState
impl Copy for ScrollState
Source§impl Debug for ScrollState
impl Debug for ScrollState
Source§impl Default for ScrollState
impl Default for ScrollState
Source§impl PartialEq for ScrollState
impl PartialEq for ScrollState
impl StructuralPartialEq for ScrollState
Auto Trait Implementations§
impl Forget for ScrollState
impl Freeze for ScrollState
impl Move for ScrollState
impl RefUnwindSafe for ScrollState
impl Send for ScrollState
impl Sync for ScrollState
impl Unpin for ScrollState
impl UnsafeUnpin for ScrollState
impl UnwindSafe for ScrollState
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