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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Test horizontal scrolling using the ScrollContainer from our library
use kael::{
div, prelude::*, px, rgb, size, App, Application, Bounds, Context, Window, WindowBounds,
WindowOptions,
};
use kael_ui::layout::ScrollContainer;
struct TestHorizontalScroll {}
impl Render for TestHorizontalScroll {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.size_full()
.flex()
.flex_col()
.gap_4()
.p_4()
.bg(kael::white())
.child(div().child("Raw GPUI (WORKS):"))
.child(
div()
.id("raw")
.h(px(200.))
.w_full()
.overflow_x_scroll()
.border_1()
.border_color(rgb(0xff0000))
.bg(rgb(0xfafafa))
.p_4()
.child(
div().w(px(2000.)).h_full().child(
div()
.flex()
.flex_row()
.flex_nowrap()
.gap_4()
.h_full()
.children((0..20).map(|i| {
div()
.w(px(150.))
.flex_shrink_0()
.h_full()
.bg(if i % 2 == 0 {
rgb(0xdbeafe)
} else {
rgb(0xfecaca)
})
.border_1()
.rounded(px(4.0))
.p_2()
.child(format!("Item {}", i + 1))
})),
),
),
)
.child(div().child("ScrollContainer::horizontal() with overlay bars:"))
.child(
ScrollContainer::horizontal()
.with_scrollbar()
.horizontal_bar_top()
.h(px(200.))
.w_full()
.border_1()
.border_color(rgb(0x00ff00))
.bg(rgb(0xfafafa))
.p(px(12.0))
.child(
div().w(px(2000.)).h_full().child(
div()
.flex()
.flex_row()
.flex_nowrap()
.gap_4()
.h_full()
.children((0..20).map(|i| {
div()
.w(px(150.))
.flex_shrink_0()
.h_full()
.bg(if i % 2 == 0 {
rgb(0xd1fae5)
} else {
rgb(0xfed7d7)
})
.border_1()
.rounded(px(4.0))
.p_2()
.child(format!("Item {}", i + 1))
})),
),
),
)
.child(div().child("ScrollContainer::horizontal() WITHOUT overlay bars:"))
.child(
ScrollContainer::horizontal()
.with_scrollbar()
.horizontal_bar_bottom()
.h(px(200.))
.w_full()
.border_1()
.border_color(rgb(0x0000ff))
.bg(rgb(0xfafafa))
.p(px(12.0))
.child(
div().w(px(2000.)).h_full().child(
div()
.flex()
.flex_row()
.flex_nowrap()
.gap_4()
.h_full()
.children((0..20).map(|i| {
div()
.w(px(150.))
.flex_shrink_0()
.h_full()
.bg(if i % 2 == 0 {
rgb(0xffe4b5)
} else {
rgb(0xe6e6fa)
})
.border_1()
.rounded(px(4.0))
.p_2()
.child(format!("Item {}", i + 1))
})),
),
),
)
}
}
fn main() {
Application::new().run(|cx: &mut App| {
let bounds = Bounds::centered(None, size(px(800.), px(500.0)), cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
..Default::default()
},
|_, cx| cx.new(|_| TestHorizontalScroll {}),
)
.unwrap();
cx.activate(true);
});
}