grid_layout.rs

 1use gpui::{
 2    App, Application, Bounds, Context, Hsla, Window, WindowBounds, WindowOptions, div, prelude::*,
 3    px, rgb, size,
 4};
 5
 6// https://en.wikipedia.org/wiki/Holy_grail_(web_design)
 7struct HolyGrailExample {}
 8
 9impl Render for HolyGrailExample {
10    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
11        let block = |color: Hsla| {
12            div()
13                .size_full()
14                .bg(color)
15                .border_1()
16                .border_dashed()
17                .rounded_md()
18                .border_color(gpui::white())
19                .items_center()
20        };
21
22        div()
23            .gap_1()
24            .id("Random")
25            .grid()
26            .bg(rgb(0x505050))
27            .size(px(500.0))
28            .shadow_lg()
29            .border_1()
30            .size_full()
31            .grid_cols(5)
32            .grid_rows(5)
33            .child(
34                block(gpui::white())
35                    .row_span(1)
36                    .col_span_full()
37                    .child("Header"),
38            )
39            .child(
40                block(gpui::red())
41                    .id("Table of contents")
42                    .row_span(1)
43                    .container_3xs(|style| style.col_span(1).row_span_auto())
44                    .h_56()
45                    .child("Table of contents"),
46            )
47            .child(
48                block(gpui::green())
49                    .col_span(3)
50                    .row_span(3)
51                    .child("Content"),
52            )
53            .child(
54                block(gpui::blue())
55                    .id("Ads")
56                    .col_span(3)
57                    .row_span(1)
58                    .container_3xs(|style| style.col_span(1).row_span(3))
59                    .child("AD :(")
60                    .text_color(gpui::white()),
61            )
62            .child(
63                block(gpui::black())
64                    .row_span(1)
65                    .col_span_full()
66                    .text_color(gpui::white())
67                    .child("Footer"),
68            )
69    }
70}
71
72fn main() {
73    Application::new().run(|cx: &mut App| {
74        let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
75        cx.open_window(
76            WindowOptions {
77                window_bounds: Some(WindowBounds::Windowed(bounds)),
78                ..Default::default()
79            },
80            |_, cx| cx.new(|_| HolyGrailExample {}),
81        )
82        .unwrap();
83        cx.activate(true);
84    });
85}