hello_world.rs

  1use gpui::{
  2    App, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, div, prelude::*, px,
  3    rgb, size,
  4};
  5use gpui_platform::application;
  6
  7struct HelloWorld {
  8    text: SharedString,
  9}
 10
 11impl Render for HelloWorld {
 12    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
 13        div()
 14            .flex()
 15            .flex_col()
 16            .gap_3()
 17            .bg(rgb(0x505050))
 18            .size(px(500.0))
 19            .justify_center()
 20            .items_center()
 21            .shadow_lg()
 22            .border_1()
 23            .border_color(rgb(0x0000ff))
 24            .text_xl()
 25            .text_color(rgb(0xffffff))
 26            .child(format!("Hello, {}!", &self.text))
 27            .child(
 28                div()
 29                    .flex()
 30                    .gap_2()
 31                    .child(
 32                        div()
 33                            .size_8()
 34                            .bg(gpui::red())
 35                            .border_1()
 36                            .border_dashed()
 37                            .rounded_md()
 38                            .border_color(gpui::white()),
 39                    )
 40                    .child(
 41                        div()
 42                            .size_8()
 43                            .bg(gpui::green())
 44                            .border_1()
 45                            .border_dashed()
 46                            .rounded_md()
 47                            .border_color(gpui::white()),
 48                    )
 49                    .child(
 50                        div()
 51                            .size_8()
 52                            .bg(gpui::blue())
 53                            .border_1()
 54                            .border_dashed()
 55                            .rounded_md()
 56                            .border_color(gpui::white()),
 57                    )
 58                    .child(
 59                        div()
 60                            .size_8()
 61                            .bg(gpui::yellow())
 62                            .border_1()
 63                            .border_dashed()
 64                            .rounded_md()
 65                            .border_color(gpui::white()),
 66                    )
 67                    .child(
 68                        div()
 69                            .size_8()
 70                            .bg(gpui::black())
 71                            .border_1()
 72                            .border_dashed()
 73                            .rounded_md()
 74                            .rounded_md()
 75                            .border_color(gpui::white()),
 76                    )
 77                    .child(
 78                        div()
 79                            .size_8()
 80                            .bg(gpui::white())
 81                            .border_1()
 82                            .border_dashed()
 83                            .rounded_md()
 84                            .border_color(gpui::black()),
 85                    ),
 86            )
 87    }
 88}
 89
 90fn main() {
 91    application().run(|cx: &mut App| {
 92        let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
 93        cx.open_window(
 94            WindowOptions {
 95                window_bounds: Some(WindowBounds::Windowed(bounds)),
 96                ..Default::default()
 97            },
 98            |_, cx| {
 99                cx.new(|_| HelloWorld {
100                    text: "World".into(),
101                })
102            },
103        )
104        .unwrap();
105        cx.activate(true);
106    });
107}