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