cursor.rs

  1use gpui::{Div, Render, Stateful};
  2use story::Story;
  3use ui::prelude::*;
  4
  5pub struct CursorStory;
  6
  7impl Render for CursorStory {
  8    type Element = Div;
  9
 10    fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
 11        let all_cursors: [(&str, Box<dyn Fn(Stateful<Div>) -> Stateful<Div>>); 19] = [
 12            (
 13                "cursor_default",
 14                Box::new(|el: Stateful<Div>| el.cursor_default()),
 15            ),
 16            (
 17                "cursor_pointer",
 18                Box::new(|el: Stateful<Div>| el.cursor_pointer()),
 19            ),
 20            (
 21                "cursor_text",
 22                Box::new(|el: Stateful<Div>| el.cursor_text()),
 23            ),
 24            (
 25                "cursor_move",
 26                Box::new(|el: Stateful<Div>| el.cursor_move()),
 27            ),
 28            (
 29                "cursor_not_allowed",
 30                Box::new(|el: Stateful<Div>| el.cursor_not_allowed()),
 31            ),
 32            (
 33                "cursor_context_menu",
 34                Box::new(|el: Stateful<Div>| el.cursor_context_menu()),
 35            ),
 36            (
 37                "cursor_crosshair",
 38                Box::new(|el: Stateful<Div>| el.cursor_crosshair()),
 39            ),
 40            (
 41                "cursor_vertical_text",
 42                Box::new(|el: Stateful<Div>| el.cursor_vertical_text()),
 43            ),
 44            (
 45                "cursor_alias",
 46                Box::new(|el: Stateful<Div>| el.cursor_alias()),
 47            ),
 48            (
 49                "cursor_copy",
 50                Box::new(|el: Stateful<Div>| el.cursor_copy()),
 51            ),
 52            (
 53                "cursor_no_drop",
 54                Box::new(|el: Stateful<Div>| el.cursor_no_drop()),
 55            ),
 56            (
 57                "cursor_grab",
 58                Box::new(|el: Stateful<Div>| el.cursor_grab()),
 59            ),
 60            (
 61                "cursor_grabbing",
 62                Box::new(|el: Stateful<Div>| el.cursor_grabbing()),
 63            ),
 64            (
 65                "cursor_col_resize",
 66                Box::new(|el: Stateful<Div>| el.cursor_col_resize()),
 67            ),
 68            (
 69                "cursor_row_resize",
 70                Box::new(|el: Stateful<Div>| el.cursor_row_resize()),
 71            ),
 72            (
 73                "cursor_n_resize",
 74                Box::new(|el: Stateful<Div>| el.cursor_n_resize()),
 75            ),
 76            (
 77                "cursor_e_resize",
 78                Box::new(|el: Stateful<Div>| el.cursor_e_resize()),
 79            ),
 80            (
 81                "cursor_s_resize",
 82                Box::new(|el: Stateful<Div>| el.cursor_s_resize()),
 83            ),
 84            (
 85                "cursor_w_resize",
 86                Box::new(|el: Stateful<Div>| el.cursor_w_resize()),
 87            ),
 88        ];
 89
 90        Story::container()
 91            .flex()
 92            .gap_1()
 93            .child(Story::title("cursor"))
 94            .children(all_cursors.map(|(name, apply_cursor)| {
 95                div().gap_1().flex().text_color(gpui::white()).child(
 96                    div()
 97                        .flex()
 98                        .items_center()
 99                        .justify_center()
100                        .id(name)
101                        .map(apply_cursor)
102                        .w_64()
103                        .h_8()
104                        .bg(gpui::red())
105                        .active(|style| style.bg(gpui::green()))
106                        .text_sm()
107                        .child(Story::label(name)),
108                )
109            }))
110    }
111}