1//! Renders a div with deep children hierarchy. This example is useful to exemplify that Zed can
2//! handle deep hierarchies (even though it cannot just yet!).
3use std::sync::LazyLock;
4
5use gpui::{App, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px, size};
6use gpui_platform::application;
7
8struct Tree {}
9
10static DEPTH: LazyLock<u64> = LazyLock::new(|| {
11 std::env::var("GPUI_TREE_DEPTH")
12 .ok()
13 .and_then(|depth| depth.parse().ok())
14 .unwrap_or_else(|| 50)
15});
16
17impl Render for Tree {
18 fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
19 let mut depth = *DEPTH;
20 static COLORS: [gpui::Hsla; 4] = [gpui::red(), gpui::blue(), gpui::green(), gpui::yellow()];
21 let mut colors = COLORS.iter().cycle().copied();
22 let mut next_div = || div().p_0p5().bg(colors.next().unwrap());
23 let mut innermost_node = next_div();
24 while depth > 0 {
25 innermost_node = next_div().child(innermost_node);
26 depth -= 1;
27 }
28 innermost_node
29 }
30}
31
32fn main() {
33 application().run(|cx: &mut App| {
34 let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
35 cx.open_window(
36 WindowOptions {
37 window_bounds: Some(WindowBounds::Windowed(bounds)),
38 ..Default::default()
39 },
40 |_, cx| cx.new(|_| Tree {}),
41 )
42 .unwrap();
43 });
44}