Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -1,23 +1,23 @@
|
|||
use editor::Editor;
|
||||
use gpui::{
|
||||
div, white, IntoElement, KeyBinding, ParentElement, Render, Styled, View, ViewContext,
|
||||
VisualContext, WindowContext,
|
||||
div, white, App, AppContext as _, Context, Entity, IntoElement, KeyBinding, ParentElement,
|
||||
Render, Styled, Window,
|
||||
};
|
||||
|
||||
pub struct AutoHeightEditorStory {
|
||||
editor: View<Editor>,
|
||||
editor: Entity<Editor>,
|
||||
}
|
||||
|
||||
impl AutoHeightEditorStory {
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
pub fn new(window: &mut Window, cx: &mut App) -> gpui::Entity<Self> {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"enter",
|
||||
editor::actions::Newline,
|
||||
Some("Editor"),
|
||||
)]);
|
||||
cx.new_view(|cx| Self {
|
||||
editor: cx.new_view(|cx| {
|
||||
let mut editor = Editor::auto_height(3, cx);
|
||||
cx.new(|cx| Self {
|
||||
editor: cx.new(|cx| {
|
||||
let mut editor = Editor::auto_height(3, window, cx);
|
||||
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
|
||||
editor
|
||||
}),
|
||||
|
@ -26,7 +26,7 @@ impl AutoHeightEditorStory {
|
|||
}
|
||||
|
||||
impl Render for AutoHeightEditorStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.bg(white())
|
||||
|
|
|
@ -5,7 +5,7 @@ use ui::prelude::*;
|
|||
pub struct CursorStory;
|
||||
|
||||
impl Render for CursorStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let all_cursors: [(&str, Box<dyn Fn(Stateful<Div>) -> Stateful<Div>>); 19] = [
|
||||
(
|
||||
"cursor_default",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use gpui::{
|
||||
colors, div, prelude::*, DefaultColor, DefaultThemeAppearance, Hsla, Render, View, ViewContext,
|
||||
WindowContext,
|
||||
colors, div, prelude::*, App, Context, DefaultColor, DefaultThemeAppearance, Entity, Hsla,
|
||||
Render, Window,
|
||||
};
|
||||
use story::Story;
|
||||
use strum::IntoEnumIterator;
|
||||
|
@ -9,13 +9,13 @@ use ui::{h_flex, ActiveTheme};
|
|||
pub struct DefaultColorsStory;
|
||||
|
||||
impl DefaultColorsStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|_cx| Self)
|
||||
pub fn model(cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|_| Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for DefaultColorsStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let appearances = [DefaultThemeAppearance::Light, DefaultThemeAppearance::Dark];
|
||||
|
||||
Story::container()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use gpui::{
|
||||
actions, div, prelude::*, FocusHandle, KeyBinding, Render, Subscription, View, WindowContext,
|
||||
actions, div, prelude::*, App, Entity, FocusHandle, KeyBinding, Render, Subscription, Window,
|
||||
};
|
||||
use ui::prelude::*;
|
||||
|
||||
|
@ -13,34 +13,34 @@ pub struct FocusStory {
|
|||
}
|
||||
|
||||
impl FocusStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
pub fn model(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
||||
cx.bind_keys([
|
||||
KeyBinding::new("cmd-a", ActionA, Some("parent")),
|
||||
KeyBinding::new("cmd-a", ActionB, Some("child-1")),
|
||||
KeyBinding::new("cmd-c", ActionC, None),
|
||||
]);
|
||||
|
||||
cx.new_view(move |cx| {
|
||||
cx.new(|cx| {
|
||||
let parent_focus = cx.focus_handle();
|
||||
let child_1_focus = cx.focus_handle();
|
||||
let child_2_focus = cx.focus_handle();
|
||||
let _focus_subscriptions = vec![
|
||||
cx.on_focus(&parent_focus, |_, _| {
|
||||
cx.on_focus(&parent_focus, window, |_, _, _| {
|
||||
println!("Parent focused");
|
||||
}),
|
||||
cx.on_blur(&parent_focus, |_, _| {
|
||||
cx.on_blur(&parent_focus, window, |_, _, _| {
|
||||
println!("Parent blurred");
|
||||
}),
|
||||
cx.on_focus(&child_1_focus, |_, _| {
|
||||
cx.on_focus(&child_1_focus, window, |_, _, _| {
|
||||
println!("Child 1 focused");
|
||||
}),
|
||||
cx.on_blur(&child_1_focus, |_, _| {
|
||||
cx.on_blur(&child_1_focus, window, |_, _, _| {
|
||||
println!("Child 1 blurred");
|
||||
}),
|
||||
cx.on_focus(&child_2_focus, |_, _| {
|
||||
cx.on_focus(&child_2_focus, window, |_, _, _| {
|
||||
println!("Child 2 focused");
|
||||
}),
|
||||
cx.on_blur(&child_2_focus, |_, _| {
|
||||
cx.on_blur(&child_2_focus, window, |_, _, _| {
|
||||
println!("Child 2 blurred");
|
||||
}),
|
||||
];
|
||||
|
@ -56,7 +56,7 @@ impl FocusStory {
|
|||
}
|
||||
|
||||
impl Render for FocusStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let color_1 = theme.status().created;
|
||||
let color_2 = theme.status().modified;
|
||||
|
@ -70,14 +70,14 @@ impl Render for FocusStory {
|
|||
.active(|style| style.bg(color_7))
|
||||
.track_focus(&self.parent_focus)
|
||||
.key_context("parent")
|
||||
.on_action(cx.listener(|_, _action: &ActionA, _cx| {
|
||||
.on_action(cx.listener(|_, _action: &ActionA, _window, _cx| {
|
||||
println!("Action A dispatched on parent");
|
||||
}))
|
||||
.on_action(cx.listener(|_, _action: &ActionB, _cx| {
|
||||
.on_action(cx.listener(|_, _action: &ActionB, _window, _cx| {
|
||||
println!("Action B dispatched on parent");
|
||||
}))
|
||||
.on_key_down(cx.listener(|_, event, _| println!("Key down on parent {:?}", event)))
|
||||
.on_key_up(cx.listener(|_, event, _| println!("Key up on parent {:?}", event)))
|
||||
.on_key_down(cx.listener(|_, event, _, _| println!("Key down on parent {:?}", event)))
|
||||
.on_key_up(cx.listener(|_, event, _, _| println!("Key up on parent {:?}", event)))
|
||||
.size_full()
|
||||
.bg(color_1)
|
||||
.focus(|style| style.bg(color_2))
|
||||
|
@ -85,7 +85,7 @@ impl Render for FocusStory {
|
|||
div()
|
||||
.track_focus(&self.child_1_focus)
|
||||
.key_context("child-1")
|
||||
.on_action(cx.listener(|_, _action: &ActionB, _cx| {
|
||||
.on_action(cx.listener(|_, _action: &ActionB, _window, _cx| {
|
||||
println!("Action B dispatched on child 1 during");
|
||||
}))
|
||||
.w_full()
|
||||
|
@ -94,25 +94,29 @@ impl Render for FocusStory {
|
|||
.focus(|style| style.bg(color_5))
|
||||
.in_focus(|style| style.bg(color_6))
|
||||
.on_key_down(
|
||||
cx.listener(|_, event, _| println!("Key down on child 1 {:?}", event)),
|
||||
cx.listener(|_, event, _, _| println!("Key down on child 1 {:?}", event)),
|
||||
)
|
||||
.on_key_up(
|
||||
cx.listener(|_, event, _, _| println!("Key up on child 1 {:?}", event)),
|
||||
)
|
||||
.on_key_up(cx.listener(|_, event, _| println!("Key up on child 1 {:?}", event)))
|
||||
.child("Child 1"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.track_focus(&self.child_2_focus)
|
||||
.key_context("child-2")
|
||||
.on_action(cx.listener(|_, _action: &ActionC, _cx| {
|
||||
.on_action(cx.listener(|_, _action: &ActionC, _window, _cx| {
|
||||
println!("Action C dispatched on child 2");
|
||||
}))
|
||||
.w_full()
|
||||
.h_6()
|
||||
.bg(color_4)
|
||||
.on_key_down(
|
||||
cx.listener(|_, event, _| println!("Key down on child 2 {:?}", event)),
|
||||
cx.listener(|_, event, _, _| println!("Key down on child 2 {:?}", event)),
|
||||
)
|
||||
.on_key_up(
|
||||
cx.listener(|_, event, _, _| println!("Key up on child 2 {:?}", event)),
|
||||
)
|
||||
.on_key_up(cx.listener(|_, event, _| println!("Key up on child 2 {:?}", event)))
|
||||
.child("Child 2"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ use std::fmt::format;
|
|||
|
||||
use gpui::{
|
||||
colors, div, prelude::*, uniform_list, DefaultColor, DefaultThemeAppearance, Hsla, Render,
|
||||
View, ViewContext, WindowContext,
|
||||
};
|
||||
use story::Story;
|
||||
use strum::IntoEnumIterator;
|
||||
|
@ -17,7 +16,7 @@ pub struct IndentGuidesStory {
|
|||
}
|
||||
|
||||
impl IndentGuidesStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
pub fn model(window: &mut Window, cx: &mut AppContext) -> Model<Self> {
|
||||
let mut depths = Vec::new();
|
||||
depths.push(0);
|
||||
depths.push(1);
|
||||
|
@ -29,18 +28,18 @@ impl IndentGuidesStory {
|
|||
depths.push(1);
|
||||
depths.push(0);
|
||||
|
||||
cx.new_view(|_cx| Self { depths })
|
||||
cx.new(|_cx| Self { depths })
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for IndentGuidesStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut ModelContext<Self>) -> impl IntoElement {
|
||||
Story::container()
|
||||
.child(Story::title("Indent guides"))
|
||||
.child(
|
||||
v_flex().size_full().child(
|
||||
uniform_list(
|
||||
cx.view().clone(),
|
||||
cx.model().clone(),
|
||||
"some-list",
|
||||
self.depths.len(),
|
||||
|this, range, cx| {
|
||||
|
@ -61,7 +60,7 @@ impl Render for IndentGuidesStory {
|
|||
)
|
||||
.with_sizing_behavior(gpui::ListSizingBehavior::Infer)
|
||||
.with_decoration(ui::indent_guides(
|
||||
cx.view().clone(),
|
||||
cx.model().clone(),
|
||||
px(16.),
|
||||
ui::IndentGuideColors {
|
||||
default: Color::Info.color(cx),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{prelude::*, Render, View};
|
||||
use gpui::{prelude::*, Entity, Render};
|
||||
use story::Story;
|
||||
use strum::IntoEnumIterator;
|
||||
use ui::prelude::*;
|
||||
|
@ -8,15 +8,15 @@ use crate::story_selector::ComponentStory;
|
|||
pub struct KitchenSinkStory;
|
||||
|
||||
impl KitchenSinkStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|_cx| Self)
|
||||
pub fn model(cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|_| Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for KitchenSinkStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let component_stories = ComponentStory::iter()
|
||||
.map(|selector| selector.story(cx))
|
||||
.map(|selector| selector.story(window, cx))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Story::container()
|
||||
|
|
|
@ -6,7 +6,7 @@ use ui::prelude::*;
|
|||
pub struct OverflowScrollStory;
|
||||
|
||||
impl Render for OverflowScrollStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container()
|
||||
.child(Story::title("Overflow Scroll"))
|
||||
.child(Story::label("`overflow_x_scroll`"))
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use fuzzy::StringMatchCandidate;
|
||||
use gpui::{div, prelude::*, KeyBinding, Render, SharedString, Styled, Task, View, WindowContext};
|
||||
use gpui::{div, prelude::*, App, Entity, KeyBinding, Render, SharedString, Styled, Task, Window};
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use std::sync::Arc;
|
||||
use ui::{prelude::*, ListItemSpacing};
|
||||
use ui::{Label, ListItem};
|
||||
|
||||
pub struct PickerStory {
|
||||
picker: View<Picker<Delegate>>,
|
||||
picker: Entity<Picker<Delegate>>,
|
||||
}
|
||||
|
||||
struct Delegate {
|
||||
|
@ -37,7 +37,7 @@ impl PickerDelegate for Delegate {
|
|||
self.candidates.len()
|
||||
}
|
||||
|
||||
fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
|
||||
fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str> {
|
||||
"Test".into()
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,8 @@ impl PickerDelegate for Delegate {
|
|||
&self,
|
||||
ix: usize,
|
||||
selected: bool,
|
||||
_cx: &mut ViewContext<Picker<Self>>,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let candidate_ix = self.matches.get(ix)?;
|
||||
// TASK: Make StringMatchCandidate::string a SharedString
|
||||
|
@ -64,12 +65,12 @@ impl PickerDelegate for Delegate {
|
|||
self.selected_ix
|
||||
}
|
||||
|
||||
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn set_selected_index(&mut self, ix: usize, _: &mut Window, cx: &mut Context<Picker<Self>>) {
|
||||
self.selected_ix = ix;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn confirm(&mut self, secondary: bool, _cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn confirm(&mut self, secondary: bool, _window: &mut Window, _cx: &mut Context<Picker<Self>>) {
|
||||
let candidate_ix = self.matches[self.selected_ix];
|
||||
let candidate = self.candidates[candidate_ix].string.clone();
|
||||
|
||||
|
@ -80,11 +81,16 @@ impl PickerDelegate for Delegate {
|
|||
}
|
||||
}
|
||||
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<Self>>) {
|
||||
cx.quit();
|
||||
}
|
||||
|
||||
fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()> {
|
||||
fn update_matches(
|
||||
&mut self,
|
||||
query: String,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> Task<()> {
|
||||
let candidates = self.candidates.clone();
|
||||
self.matches = cx
|
||||
.background_executor()
|
||||
|
@ -105,8 +111,8 @@ impl PickerDelegate for Delegate {
|
|||
}
|
||||
|
||||
impl PickerStory {
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|cx| {
|
||||
pub fn new(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|cx| {
|
||||
cx.bind_keys([
|
||||
KeyBinding::new("up", menu::SelectPrev, Some("picker")),
|
||||
KeyBinding::new("pageup", menu::SelectFirst, Some("picker")),
|
||||
|
@ -126,7 +132,7 @@ impl PickerStory {
|
|||
]);
|
||||
|
||||
PickerStory {
|
||||
picker: cx.new_view(|cx| {
|
||||
picker: cx.new(|cx| {
|
||||
let mut delegate = Delegate::new(&[
|
||||
"Baguette (France)",
|
||||
"Baklava (Turkey)",
|
||||
|
@ -178,10 +184,10 @@ impl PickerStory {
|
|||
"Tzatziki (Greece)",
|
||||
"Wiener Schnitzel (Austria)",
|
||||
]);
|
||||
delegate.update_matches("".into(), cx).detach();
|
||||
delegate.update_matches("".into(), window, cx).detach();
|
||||
|
||||
let picker = Picker::uniform_list(delegate, cx);
|
||||
picker.focus(cx);
|
||||
let picker = Picker::uniform_list(delegate, window, cx);
|
||||
picker.focus(window, cx);
|
||||
picker
|
||||
}),
|
||||
}
|
||||
|
@ -190,7 +196,7 @@ impl PickerStory {
|
|||
}
|
||||
|
||||
impl Render for PickerStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.bg(cx.theme().styles.colors.background)
|
||||
.size_full()
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use gpui::{div, prelude::*, px, Render, SharedString, Styled, View, WindowContext};
|
||||
use gpui::{div, prelude::*, px, App, Entity, Render, SharedString, Styled, Window};
|
||||
use ui::prelude::*;
|
||||
use ui::Tooltip;
|
||||
|
||||
pub struct ScrollStory;
|
||||
|
||||
impl ScrollStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<ScrollStory> {
|
||||
cx.new_view(|_cx| ScrollStory)
|
||||
pub fn model(cx: &mut App) -> Entity<ScrollStory> {
|
||||
cx.new(|_| ScrollStory)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ScrollStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let color_1 = theme.status().created;
|
||||
let color_2 = theme.status().modified;
|
||||
|
@ -35,8 +35,8 @@ impl Render for ScrollStory {
|
|||
color_2
|
||||
};
|
||||
div()
|
||||
.id(id)
|
||||
.tooltip(move |cx| Tooltip::text(format!("{}, {}", row, column), cx))
|
||||
.id(id.clone())
|
||||
.tooltip(Tooltip::text(id))
|
||||
.bg(bg)
|
||||
.size(px(100_f32))
|
||||
.when(row >= 5 && column >= 5, |d| {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use gpui::{
|
||||
div, green, red, HighlightStyle, InteractiveText, IntoElement, ParentElement, Render, Styled,
|
||||
StyledText, View, ViewContext, VisualContext, WindowContext,
|
||||
div, green, red, App, AppContext as _, Context, Entity, HighlightStyle, InteractiveText,
|
||||
IntoElement, ParentElement, Render, Styled, StyledText, Window,
|
||||
};
|
||||
use indoc::indoc;
|
||||
use story::*;
|
||||
|
@ -8,13 +8,13 @@ use story::*;
|
|||
pub struct TextStory;
|
||||
|
||||
impl TextStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|_cx| Self)
|
||||
pub fn model(cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|_| Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for TextStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container()
|
||||
.child(Story::title("Text"))
|
||||
.children(vec![
|
||||
|
@ -82,7 +82,7 @@ impl Render for TextStory {
|
|||
InteractiveText::new(
|
||||
"interactive",
|
||||
StyledText::new("Hello world, how is it going?").with_highlights(
|
||||
&cx.text_style(),
|
||||
&window.text_style(),
|
||||
[
|
||||
(
|
||||
6..11,
|
||||
|
@ -94,14 +94,14 @@ impl Render for TextStory {
|
|||
],
|
||||
),
|
||||
)
|
||||
.on_click(vec![2..4, 1..3, 7..9], |range_ix, _cx| {
|
||||
.on_click(vec![2..4, 1..3, 7..9], |range_ix, _, _cx| {
|
||||
println!("Clicked range {range_ix}");
|
||||
}),
|
||||
)
|
||||
.usage(indoc! {r##"
|
||||
InteractiveText::new(
|
||||
"interactive",
|
||||
StyledText::new("Hello world, how is it going?").with_highlights(&cx.text_style(), [
|
||||
StyledText::new("Hello world, how is it going?").with_highlights(&window.text_style(), [
|
||||
(6..11, HighlightStyle {
|
||||
background_color: Some(green()),
|
||||
..Default::default()
|
||||
|
|
|
@ -6,23 +6,23 @@ use ui::prelude::*;
|
|||
pub struct ViewportUnitsStory;
|
||||
|
||||
impl Render for ViewportUnitsStory {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container().child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.child(
|
||||
div()
|
||||
.w(vw(0.5, cx))
|
||||
.h(vh(0.8, cx))
|
||||
.w(vw(0.5, window))
|
||||
.h(vh(0.8, window))
|
||||
.bg(gpui::red())
|
||||
.text_color(gpui::white())
|
||||
.child("50vw, 80vh"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.w(vw(0.25, cx))
|
||||
.h(vh(0.33, cx))
|
||||
.w(vw(0.25, window))
|
||||
.h(vh(0.33, window))
|
||||
.bg(gpui::green())
|
||||
.text_color(gpui::white())
|
||||
.child("25vw, 33vh"),
|
||||
|
|
|
@ -6,7 +6,7 @@ use ui::{prelude::*, utils::WithRemSize};
|
|||
pub struct WithRemSizeStory;
|
||||
|
||||
impl Render for WithRemSizeStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container().child(
|
||||
Example::new(16., gpui::red())
|
||||
.child(
|
||||
|
@ -47,7 +47,7 @@ impl ParentElement for Example {
|
|||
}
|
||||
|
||||
impl RenderOnce for Example {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||
WithRemSize::new(self.rem_size).child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::stories::*;
|
|||
use anyhow::anyhow;
|
||||
use clap::builder::PossibleValue;
|
||||
use clap::ValueEnum;
|
||||
use gpui::{AnyView, VisualContext};
|
||||
use gpui::AnyView;
|
||||
use strum::{EnumIter, EnumString, IntoEnumIterator};
|
||||
use ui::prelude::*;
|
||||
|
||||
|
@ -43,40 +43,40 @@ pub enum ComponentStory {
|
|||
}
|
||||
|
||||
impl ComponentStory {
|
||||
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
|
||||
pub fn story(&self, window: &mut Window, cx: &mut App) -> AnyView {
|
||||
match self {
|
||||
Self::ApplicationMenu => cx
|
||||
.new_view(|cx| title_bar::ApplicationMenuStory::new(cx))
|
||||
.new(|cx| title_bar::ApplicationMenuStory::new(window, cx))
|
||||
.into(),
|
||||
Self::AutoHeightEditor => AutoHeightEditorStory::new(cx).into(),
|
||||
Self::Avatar => cx.new_view(|_| ui::AvatarStory).into(),
|
||||
Self::Button => cx.new_view(|_| ui::ButtonStory).into(),
|
||||
Self::AutoHeightEditor => AutoHeightEditorStory::new(window, cx).into(),
|
||||
Self::Avatar => cx.new(|_| ui::AvatarStory).into(),
|
||||
Self::Button => cx.new(|_| ui::ButtonStory).into(),
|
||||
Self::CollabNotification => cx
|
||||
.new_view(|_| collab_ui::notifications::CollabNotificationStory)
|
||||
.new(|_| collab_ui::notifications::CollabNotificationStory)
|
||||
.into(),
|
||||
Self::ContextMenu => cx.new_view(|_| ui::ContextMenuStory).into(),
|
||||
Self::Cursor => cx.new_view(|_| crate::stories::CursorStory).into(),
|
||||
Self::DefaultColors => DefaultColorsStory::view(cx).into(),
|
||||
Self::Disclosure => cx.new_view(|_| ui::DisclosureStory).into(),
|
||||
Self::Focus => FocusStory::view(cx).into(),
|
||||
Self::Icon => cx.new_view(|_| ui::IconStory).into(),
|
||||
Self::IconButton => cx.new_view(|_| ui::IconButtonStory).into(),
|
||||
Self::Keybinding => cx.new_view(|_| ui::KeybindingStory).into(),
|
||||
Self::Label => cx.new_view(|_| ui::LabelStory).into(),
|
||||
Self::List => cx.new_view(|_| ui::ListStory).into(),
|
||||
Self::ListHeader => cx.new_view(|_| ui::ListHeaderStory).into(),
|
||||
Self::ListItem => cx.new_view(|_| ui::ListItemStory).into(),
|
||||
Self::OverflowScroll => cx.new_view(|_| crate::stories::OverflowScrollStory).into(),
|
||||
Self::Picker => PickerStory::new(cx).into(),
|
||||
Self::Scroll => ScrollStory::view(cx).into(),
|
||||
Self::Tab => cx.new_view(|_| ui::TabStory).into(),
|
||||
Self::TabBar => cx.new_view(|_| ui::TabBarStory).into(),
|
||||
Self::Text => TextStory::view(cx).into(),
|
||||
Self::ToggleButton => cx.new_view(|_| ui::ToggleButtonStory).into(),
|
||||
Self::ToolStrip => cx.new_view(|_| ui::ToolStripStory).into(),
|
||||
Self::ViewportUnits => cx.new_view(|_| crate::stories::ViewportUnitsStory).into(),
|
||||
Self::WithRemSize => cx.new_view(|_| crate::stories::WithRemSizeStory).into(),
|
||||
Self::Vector => cx.new_view(|_| ui::VectorStory).into(),
|
||||
Self::ContextMenu => cx.new(|_| ui::ContextMenuStory).into(),
|
||||
Self::Cursor => cx.new(|_| crate::stories::CursorStory).into(),
|
||||
Self::DefaultColors => DefaultColorsStory::model(cx).into(),
|
||||
Self::Disclosure => cx.new(|_| ui::DisclosureStory).into(),
|
||||
Self::Focus => FocusStory::model(window, cx).into(),
|
||||
Self::Icon => cx.new(|_| ui::IconStory).into(),
|
||||
Self::IconButton => cx.new(|_| ui::IconButtonStory).into(),
|
||||
Self::Keybinding => cx.new(|_| ui::KeybindingStory).into(),
|
||||
Self::Label => cx.new(|_| ui::LabelStory).into(),
|
||||
Self::List => cx.new(|_| ui::ListStory).into(),
|
||||
Self::ListHeader => cx.new(|_| ui::ListHeaderStory).into(),
|
||||
Self::ListItem => cx.new(|_| ui::ListItemStory).into(),
|
||||
Self::OverflowScroll => cx.new(|_| crate::stories::OverflowScrollStory).into(),
|
||||
Self::Picker => PickerStory::new(window, cx).into(),
|
||||
Self::Scroll => ScrollStory::model(cx).into(),
|
||||
Self::Tab => cx.new(|_| ui::TabStory).into(),
|
||||
Self::TabBar => cx.new(|_| ui::TabBarStory).into(),
|
||||
Self::Text => TextStory::model(cx).into(),
|
||||
Self::ToggleButton => cx.new(|_| ui::ToggleButtonStory).into(),
|
||||
Self::ToolStrip => cx.new(|_| ui::ToolStripStory).into(),
|
||||
Self::ViewportUnits => cx.new(|_| crate::stories::ViewportUnitsStory).into(),
|
||||
Self::WithRemSize => cx.new(|_| crate::stories::WithRemSizeStory).into(),
|
||||
Self::Vector => cx.new(|_| ui::VectorStory).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl FromStr for StorySelector {
|
|||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(raw_story_name: &str) -> std::result::Result<Self, Self::Err> {
|
||||
use anyhow::Context;
|
||||
use anyhow::Context as _;
|
||||
|
||||
let story = raw_story_name.to_ascii_lowercase();
|
||||
|
||||
|
@ -111,10 +111,10 @@ impl FromStr for StorySelector {
|
|||
}
|
||||
|
||||
impl StorySelector {
|
||||
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
|
||||
pub fn story(&self, window: &mut Window, cx: &mut App) -> AnyView {
|
||||
match self {
|
||||
Self::Component(component_story) => component_story.story(cx),
|
||||
Self::KitchenSink => KitchenSinkStory::view(cx).into(),
|
||||
Self::Component(component_story) => component_story.story(window, cx),
|
||||
Self::KitchenSink => KitchenSinkStory::model(cx).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ use std::sync::Arc;
|
|||
use clap::Parser;
|
||||
use dialoguer::FuzzySelect;
|
||||
use gpui::{
|
||||
div, px, size, AnyView, AppContext, Bounds, Render, ViewContext, VisualContext, WindowBounds,
|
||||
WindowOptions,
|
||||
div, px, size, AnyView, App, Bounds, Context, Render, Window, WindowBounds, WindowOptions,
|
||||
};
|
||||
use log::LevelFilter;
|
||||
use project::Project;
|
||||
|
@ -65,7 +64,7 @@ fn main() {
|
|||
});
|
||||
let theme_name = args.theme.unwrap_or("One Dark".to_string());
|
||||
|
||||
gpui::App::new().with_assets(Assets).run(move |cx| {
|
||||
gpui::Application::new().with_assets(Assets).run(move |cx| {
|
||||
load_embedded_fonts(cx).unwrap();
|
||||
|
||||
let http_client = ReqwestClient::user_agent("zed_storybook").unwrap();
|
||||
|
@ -95,10 +94,10 @@ fn main() {
|
|||
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||
..Default::default()
|
||||
},
|
||||
move |cx| {
|
||||
theme::setup_ui_font(cx);
|
||||
move |window, cx| {
|
||||
theme::setup_ui_font(window, cx);
|
||||
|
||||
cx.new_view(|cx| StoryWrapper::new(selector.story(cx)))
|
||||
cx.new(|cx| StoryWrapper::new(selector.story(window, cx)))
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -118,7 +117,7 @@ impl StoryWrapper {
|
|||
}
|
||||
|
||||
impl Render for StoryWrapper {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
|
@ -128,7 +127,7 @@ impl Render for StoryWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_embedded_fonts(cx: &AppContext) -> gpui::Result<()> {
|
||||
fn load_embedded_fonts(cx: &App) -> gpui::Result<()> {
|
||||
let font_paths = cx.asset_source().list("fonts")?;
|
||||
let mut embedded_fonts = Vec::new();
|
||||
for font_path in font_paths {
|
||||
|
@ -144,15 +143,15 @@ fn load_embedded_fonts(cx: &AppContext) -> gpui::Result<()> {
|
|||
cx.text_system().add_fonts(embedded_fonts)
|
||||
}
|
||||
|
||||
fn load_storybook_keymap(cx: &mut AppContext) {
|
||||
fn load_storybook_keymap(cx: &mut App) {
|
||||
cx.bind_keys(KeymapFile::load_asset("keymaps/storybook.json", cx).unwrap());
|
||||
}
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.on_action(quit);
|
||||
}
|
||||
|
||||
fn quit(_: &Quit, cx: &mut AppContext) {
|
||||
fn quit(_: &Quit, cx: &mut App) {
|
||||
cx.spawn(|cx| async move {
|
||||
cx.update(|cx| cx.quit())?;
|
||||
anyhow::Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue