pattern.rs

  1use gpui::{
  2    div, linear_color_stop, linear_gradient, pattern_slash, prelude::*, px, rgb, size, App,
  3    AppContext, Application, Bounds, Context, Window, WindowBounds, WindowOptions,
  4};
  5
  6struct PatternExample;
  7
  8impl Render for PatternExample {
  9    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
 10        div()
 11            .flex()
 12            .flex_col()
 13            .gap_3()
 14            .bg(rgb(0xffffff))
 15            .size(px(600.0))
 16            .justify_center()
 17            .items_center()
 18            .shadow_lg()
 19            .text_xl()
 20            .text_color(rgb(0x000000))
 21            .child("Pattern Example")
 22            .child(
 23                div()
 24                    .flex()
 25                    .flex_col()
 26                    .border_1()
 27                    .border_color(gpui::blue())
 28                    .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(gpui::red())))
 29                    .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(gpui::red())))
 30                    .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(gpui::red())))
 31                    .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash(gpui::red()))),
 32            )
 33            .child(
 34                div()
 35                    .flex()
 36                    .flex_col()
 37                    .border_1()
 38                    .border_color(gpui::blue())
 39                    .bg(gpui::green().opacity(0.16))
 40                    .child("Elements the same height should align")
 41                    .child(
 42                        div()
 43                            .w(px(256.0))
 44                            .h(px(56.0))
 45                            .bg(pattern_slash(gpui::red())),
 46                    )
 47                    .child(
 48                        div()
 49                            .w(px(256.0))
 50                            .h(px(56.0))
 51                            .bg(pattern_slash(gpui::green())),
 52                    )
 53                    .child(
 54                        div()
 55                            .w(px(256.0))
 56                            .h(px(56.0))
 57                            .bg(pattern_slash(gpui::blue())),
 58                    )
 59                    .child(
 60                        div()
 61                            .w(px(256.0))
 62                            .h(px(26.0))
 63                            .bg(pattern_slash(gpui::yellow())),
 64                    ),
 65            )
 66            .child(
 67                div()
 68                    .border_1()
 69                    .border_color(gpui::blue())
 70                    .w(px(240.0))
 71                    .h(px(40.0))
 72                    .bg(gpui::red()),
 73            )
 74            .child(
 75                div()
 76                    .border_1()
 77                    .border_color(gpui::blue())
 78                    .w(px(240.0))
 79                    .h(px(40.0))
 80                    .bg(linear_gradient(
 81                        45.,
 82                        linear_color_stop(gpui::red(), 0.),
 83                        linear_color_stop(gpui::blue(), 1.),
 84                    )),
 85            )
 86    }
 87}
 88
 89fn main() {
 90    Application::new().run(|cx: &mut App| {
 91        let bounds = Bounds::centered(None, size(px(600.0), px(600.0)), cx);
 92        cx.open_window(
 93            WindowOptions {
 94                window_bounds: Some(WindowBounds::Windowed(bounds)),
 95                ..Default::default()
 96            },
 97            |_window, cx| cx.new(|_cx| PatternExample),
 98        )
 99        .unwrap();
100
101        cx.activate(true);
102    });
103}