1use std::fmt::format;
2
3use gpui::{
4 DefaultColor, DefaultThemeAppearance, Hsla, Render, colors, div, prelude::*, uniform_list,
5};
6use story::Story;
7use strum::IntoEnumIterator;
8use ui::{
9 AbsoluteLength, ActiveTheme, Color, DefiniteLength, Label, LabelCommon, h_flex, px, v_flex,
10};
11
12const LENGTH: usize = 100;
13
14pub struct IndentGuidesStory {
15 depths: Vec<usize>,
16}
17
18impl IndentGuidesStory {
19 pub fn model(window: &mut Window, cx: &mut AppContext) -> Model<Self> {
20 let mut depths = Vec::new();
21 depths.push(0);
22 depths.push(1);
23 depths.push(2);
24 for _ in 0..LENGTH - 6 {
25 depths.push(3);
26 }
27 depths.push(2);
28 depths.push(1);
29 depths.push(0);
30
31 cx.new(|_cx| Self { depths })
32 }
33}
34
35impl Render for IndentGuidesStory {
36 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
37 Story::container(cx)
38 .child(Story::title("Indent guides"))
39 .child(
40 v_flex().size_full().child(
41 uniform_list(
42 cx.entity().clone(),
43 "some-list",
44 self.depths.len(),
45 |this, range, cx| {
46 this.depths
47 .iter()
48 .enumerate()
49 .skip(range.start)
50 .take(range.end - range.start)
51 .map(|(i, depth)| {
52 div()
53 .pl(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(
54 16. * (*depth as f32),
55 ))))
56 .child(Label::new(format!("Item {}", i)).color(Color::Info))
57 })
58 .collect()
59 },
60 )
61 .with_sizing_behavior(gpui::ListSizingBehavior::Infer)
62 .with_decoration(ui::indent_guides(
63 cx.entity().clone(),
64 px(16.),
65 ui::IndentGuideColors {
66 default: Color::Info.color(cx),
67 hovered: Color::Accent.color(cx),
68 active: Color::Accent.color(cx),
69 },
70 |this, range, cx| {
71 this.depths
72 .iter()
73 .skip(range.start)
74 .take(range.end - range.start)
75 .cloned()
76 .collect()
77 },
78 )),
79 ),
80 )
81 }
82}