1#![cfg_attr(target_family = "wasm", no_main)]
2
3use gpui::{App, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px, size};
4use gpui_platform::application;
5
6struct Scrollable {}
7
8impl Render for Scrollable {
9 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
10 div()
11 .size_full()
12 .id("vertical")
13 .p_4()
14 .overflow_scroll()
15 .bg(gpui::white())
16 .child("Example for test 2 way scroll in nested layout")
17 .child(
18 div()
19 .h(px(5000.))
20 .border_1()
21 .border_color(gpui::blue())
22 .bg(gpui::blue().opacity(0.05))
23 .p_4()
24 .child(
25 div()
26 .mb_5()
27 .w_full()
28 .id("horizontal")
29 .overflow_scroll()
30 .child(
31 div()
32 .w(px(2000.))
33 .h(px(150.))
34 .bg(gpui::green().opacity(0.1))
35 .hover(|this| this.bg(gpui::green().opacity(0.2)))
36 .border_1()
37 .border_color(gpui::green())
38 .p_4()
39 .child("Scroll Horizontal"),
40 ),
41 )
42 .child("Scroll Vertical"),
43 )
44 }
45}
46
47fn run_example() {
48 application().run(|cx: &mut App| {
49 let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
50 cx.open_window(
51 WindowOptions {
52 window_bounds: Some(WindowBounds::Windowed(bounds)),
53 ..Default::default()
54 },
55 |_, cx| cx.new(|_| Scrollable {}),
56 )
57 .unwrap();
58 cx.activate(true);
59 });
60}
61
62#[cfg(not(target_family = "wasm"))]
63fn main() {
64 run_example();
65}
66
67#[cfg(target_family = "wasm")]
68#[wasm_bindgen::prelude::wasm_bindgen(start)]
69pub fn start() {
70 gpui_platform::web_init();
71 run_example();
72}