pattern.rs

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