-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.rs
32 lines (27 loc) · 935 Bytes
/
chat.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use cursive::{
event::*,
view::{scroll::*, *},
views::*,
With,
};
pub fn scroll_view() -> impl View {
ScrollView::new(TextView::new(String::new()).with_name("chat"))
.scroll_strategy(ScrollStrategy::StickToBottom)
.with_name("scroll")
.scrollable()
.wrap_with(OnEventView::new)
.on_pre_event_inner(Key::PageUp, |v, _| {
let scroller = v.get_scroller_mut();
if scroller.can_scroll_up() {
scroller.scroll_up(scroller.last_outer_size().y.saturating_sub(1));
}
Some(EventResult::Consumed(None))
})
.on_pre_event_inner(Key::PageDown, |v, _| {
let scroller = v.get_scroller_mut();
if scroller.can_scroll_down() {
scroller.scroll_down(scroller.last_outer_size().y.saturating_sub(1));
}
Some(EventResult::Consumed(None))
})
}