Fix IndentGuides story (#32781)

This PR updates the `Model` to `Entity` also fixes the
`IndentGuidesStory`. In this
[commit](6fca1d2b0b),
`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
This commit is contained in:
Alex Shi 2025-07-01 23:43:39 +08:00 committed by GitHub
parent 351ba5023b
commit 31b7786be7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 18 deletions

View file

@ -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::*;

View file

@ -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)

View file

@ -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(),
}
}
}

View file

@ -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));

View file

@ -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>,