Fix IndentGuides story (#32781)

Alex Shi created

This PR updates the `Model` to `Entity` also fixes the
`IndentGuidesStory`. In this
[commit](https://github.com/zed-industries/zed/commit/6fca1d2b0ba93cdbc3255657a990828a0f22b199),
`Entity<T>` replaces `View<T>`/`Model<T>`.

Other than this, I noticed the storybook fails on my MacOS and Ubuntu,
see error below

```
thread 'main' panicked at crates/gpui/src/colors.rs:99:15:
called `Result::unwrap()` on an `Err` value: no state of type gpui::colors::GlobalColors exists
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

This was resolved by explicitly specifying `GlobalColors` in Storybook.

Release Notes:

- N/A

Change summary

crates/storybook/src/stories.rs               |  2 +
crates/storybook/src/stories/indent_guides.rs | 28 +++++++++------------
crates/storybook/src/story_selector.rs        |  2 +
crates/storybook/src/storybook.rs             |  6 +++
crates/ui_input/src/ui_input.rs               |  2 
5 files changed, 22 insertions(+), 18 deletions(-)

Detailed changes

crates/storybook/src/stories.rs 🔗

@@ -1,6 +1,7 @@
 mod auto_height_editor;
 mod cursor;
 mod focus;
+mod indent_guides;
 mod kitchen_sink;
 mod overflow_scroll;
 mod picker;
@@ -12,6 +13,7 @@ mod with_rem_size;
 pub use auto_height_editor::*;
 pub use cursor::*;
 pub use focus::*;
+pub use indent_guides::*;
 pub use kitchen_sink::*;
 pub use overflow_scroll::*;
 pub use picker::*;

crates/storybook/src/stories/indent_guides.rs 🔗

@@ -1,13 +1,10 @@
-use std::fmt::format;
+use std::ops::Range;
+
+use gpui::{Entity, Render, div, uniform_list};
+use gpui::{prelude::*, *};
+use ui::{AbsoluteLength, Color, DefiniteLength, Label, LabelCommon, px, v_flex};
 
-use gpui::{
-    DefaultColor, DefaultThemeAppearance, Hsla, Render, colors, div, prelude::*, uniform_list,
-};
 use story::Story;
-use strum::IntoEnumIterator;
-use ui::{
-    AbsoluteLength, ActiveTheme, Color, DefiniteLength, Label, LabelCommon, h_flex, px, v_flex,
-};
 
 const LENGTH: usize = 100;
 
@@ -16,7 +13,7 @@ pub struct IndentGuidesStory {
 }
 
 impl IndentGuidesStory {
-    pub fn model(window: &mut Window, cx: &mut AppContext) -> Model<Self> {
+    pub fn model(_window: &mut Window, cx: &mut App) -> Entity<Self> {
         let mut depths = Vec::new();
         depths.push(0);
         depths.push(1);
@@ -33,16 +30,15 @@ impl IndentGuidesStory {
 }
 
 impl Render for IndentGuidesStory {
-    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
+    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
         Story::container(cx)
-            .child(Story::title("Indent guides"))
+            .child(Story::title("Indent guides", cx))
             .child(
                 v_flex().size_full().child(
                     uniform_list(
-                        cx.entity().clone(),
                         "some-list",
                         self.depths.len(),
-                        |this, range, cx| {
+                        cx.processor(move |this, range: Range<usize>, _window, _cx| {
                             this.depths
                                 .iter()
                                 .enumerate()
@@ -56,7 +52,7 @@ impl Render for IndentGuidesStory {
                                         .child(Label::new(format!("Item {}", i)).color(Color::Info))
                                 })
                                 .collect()
-                        },
+                        }),
                     )
                     .with_sizing_behavior(gpui::ListSizingBehavior::Infer)
                     .with_decoration(ui::indent_guides(
@@ -64,10 +60,10 @@ impl Render for IndentGuidesStory {
                         px(16.),
                         ui::IndentGuideColors {
                             default: Color::Info.color(cx),
-                            hovered: Color::Accent.color(cx),
+                            hover: Color::Accent.color(cx),
                             active: Color::Accent.color(cx),
                         },
-                        |this, range, cx| {
+                        |this, range, _cx, _context| {
                             this.depths
                                 .iter()
                                 .skip(range.start)

crates/storybook/src/story_selector.rs 🔗

@@ -31,6 +31,7 @@ pub enum ComponentStory {
     ToggleButton,
     ViewportUnits,
     WithRemSize,
+    IndentGuides,
 }
 
 impl ComponentStory {
@@ -60,6 +61,7 @@ impl ComponentStory {
             Self::ToggleButton => cx.new(|_| ui::ToggleButtonStory).into(),
             Self::ViewportUnits => cx.new(|_| crate::stories::ViewportUnitsStory).into(),
             Self::WithRemSize => cx.new(|_| crate::stories::WithRemSizeStory).into(),
+            Self::IndentGuides => crate::stories::IndentGuidesStory::model(window, cx).into(),
         }
     }
 }

crates/storybook/src/storybook.rs 🔗

@@ -9,7 +9,9 @@ use std::sync::Arc;
 use clap::Parser;
 use dialoguer::FuzzySelect;
 use gpui::{
-    AnyView, App, Bounds, Context, Render, Window, WindowBounds, WindowOptions, div, px, size,
+    AnyView, App, Bounds, Context, Render, Window, WindowBounds, WindowOptions,
+    colors::{Colors, GlobalColors},
+    div, px, size,
 };
 use log::LevelFilter;
 use project::Project;
@@ -68,6 +70,8 @@ fn main() {
     gpui::Application::new().with_assets(Assets).run(move |cx| {
         load_embedded_fonts(cx).unwrap();
 
+        cx.set_global(GlobalColors(Arc::new(Colors::default())));
+
         let http_client = ReqwestClient::user_agent("zed_storybook").unwrap();
         cx.set_http_client(Arc::new(http_client));
 

crates/ui_input/src/ui_input.rs 🔗

@@ -29,7 +29,7 @@ pub struct SingleLineInput {
     label: Option<SharedString>,
     /// The placeholder text for the text field.
     placeholder: SharedString,
-    /// Exposes the underlying [`Model<Editor>`] to allow for customizing the editor beyond the provided API.
+    /// Exposes the underlying [`Entity<Editor>`] to allow for customizing the editor beyond the provided API.
     ///
     /// This likely will only be public in the short term, ideally the API will be expanded to cover necessary use cases.
     pub editor: Entity<Editor>,