forked from marc2332/freya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolled_scroll.rs
77 lines (70 loc) · 1.91 KB
/
controlled_scroll.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use freya::prelude::*;
fn main() {
launch_with_props(app, "Controlled Example", (600.0, 600.0));
}
fn app() -> Element {
let mut scroll_controller = use_scroll_controller(|| ScrollConfig {
default_vertical_position: ScrollPosition::End,
..Default::default()
});
let scroll_to_top = move |_| {
scroll_controller.scroll_to(ScrollPosition::Start, ScrollDirection::Vertical);
};
let scroll_to_bottom = move |_| {
scroll_controller.scroll_to(ScrollPosition::End, ScrollDirection::Vertical);
};
rsx!(
rect {
height: "fill",
width: "fill",
direction: "horizontal",
ScrollView {
scroll_controller,
theme: theme_with!(ScrollViewTheme {
width: "50%".into(),
}),
Button {
onclick: scroll_to_bottom,
label {
"Scroll to Bottom"
}
}
Card {}
Card {}
Card {}
}
ScrollView {
scroll_controller,
theme: theme_with!(ScrollViewTheme {
width: "50%".into(),
}),
Card {}
Card {}
Card {}
Button {
onclick: scroll_to_top,
label {
"Scroll to Top"
}
}
}
}
)
}
#[component]
fn Card() -> Element {
rsx!(
rect {
border: "15 solid rgb(43,106,208)",
height: "220",
width: "420",
background: "white",
padding: "25",
label { "Scroll..." }
}
)
}