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,4 +1,4 @@
|
|||
use gpui::{div, hsla, prelude::*, AnyView, ElementId, Hsla, IntoElement, Styled, WindowContext};
|
||||
use gpui::{div, hsla, prelude::*, AnyView, ElementId, Hsla, IntoElement, Styled, Window};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::utils::is_light;
|
||||
|
@ -41,10 +41,10 @@ pub struct Checkbox {
|
|||
id: ElementId,
|
||||
toggle_state: ToggleState,
|
||||
disabled: bool,
|
||||
on_click: Option<Box<dyn Fn(&ToggleState, &mut WindowContext) + 'static>>,
|
||||
on_click: Option<Box<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>>,
|
||||
filled: bool,
|
||||
style: ToggleStyle,
|
||||
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,
|
||||
tooltip: Option<Box<dyn Fn(&mut Window, &mut App) -> AnyView>>,
|
||||
}
|
||||
|
||||
impl Checkbox {
|
||||
|
@ -70,7 +70,7 @@ impl Checkbox {
|
|||
/// Binds a handler to the [`Checkbox`] that will be called when clicked.
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl Fn(&ToggleState, &mut WindowContext) + 'static,
|
||||
handler: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
self.on_click = Some(Box::new(handler));
|
||||
self
|
||||
|
@ -95,14 +95,14 @@ impl Checkbox {
|
|||
}
|
||||
|
||||
/// Sets the tooltip for the checkbox.
|
||||
pub fn tooltip(mut self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self {
|
||||
pub fn tooltip(mut self, tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static) -> Self {
|
||||
self.tooltip = Some(Box::new(tooltip));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Checkbox {
|
||||
fn bg_color(&self, cx: &WindowContext) -> Hsla {
|
||||
fn bg_color(&self, cx: &App) -> Hsla {
|
||||
let style = self.style.clone();
|
||||
match (style, self.filled) {
|
||||
(ToggleStyle::Ghost, false) => cx.theme().colors().ghost_element_background,
|
||||
|
@ -114,7 +114,7 @@ impl Checkbox {
|
|||
}
|
||||
}
|
||||
|
||||
fn border_color(&self, cx: &WindowContext) -> Hsla {
|
||||
fn border_color(&self, cx: &App) -> Hsla {
|
||||
if self.disabled {
|
||||
return cx.theme().colors().border_disabled;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ impl Checkbox {
|
|||
}
|
||||
|
||||
impl RenderOnce for Checkbox {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let group_id = format!("checkbox_group_{:?}", self.id);
|
||||
let icon = match self.toggle_state {
|
||||
ToggleState::Selected => Some(Icon::new(IconName::Check).size(IconSize::Small).color(
|
||||
|
@ -181,11 +181,13 @@ impl RenderOnce for Checkbox {
|
|||
.when_some(
|
||||
self.on_click.filter(|_| !self.disabled),
|
||||
|this, on_click| {
|
||||
this.on_click(move |_, cx| on_click(&self.toggle_state.inverse(), cx))
|
||||
this.on_click(move |_, window, cx| {
|
||||
on_click(&self.toggle_state.inverse(), window, cx)
|
||||
})
|
||||
},
|
||||
)
|
||||
.when_some(self.tooltip, |this, tooltip| {
|
||||
this.tooltip(move |cx| tooltip(cx))
|
||||
this.tooltip(move |window, cx| tooltip(window, cx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +198,7 @@ pub struct CheckboxWithLabel {
|
|||
id: ElementId,
|
||||
label: Label,
|
||||
checked: ToggleState,
|
||||
on_click: Arc<dyn Fn(&ToggleState, &mut WindowContext) + 'static>,
|
||||
on_click: Arc<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>,
|
||||
filled: bool,
|
||||
style: ToggleStyle,
|
||||
}
|
||||
|
@ -207,7 +209,7 @@ impl CheckboxWithLabel {
|
|||
id: impl Into<ElementId>,
|
||||
label: Label,
|
||||
checked: ToggleState,
|
||||
on_click: impl Fn(&ToggleState, &mut WindowContext) + 'static,
|
||||
on_click: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
|
@ -239,7 +241,7 @@ impl CheckboxWithLabel {
|
|||
}
|
||||
|
||||
impl RenderOnce for CheckboxWithLabel {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
h_flex()
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.child(
|
||||
|
@ -248,16 +250,16 @@ impl RenderOnce for CheckboxWithLabel {
|
|||
.when(self.filled, Checkbox::fill)
|
||||
.on_click({
|
||||
let on_click = self.on_click.clone();
|
||||
move |checked, cx| {
|
||||
(on_click)(checked, cx);
|
||||
move |checked, window, cx| {
|
||||
(on_click)(checked, window, cx);
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id(SharedString::from(format!("{}-label", self.id)))
|
||||
.on_click(move |_event, cx| {
|
||||
(self.on_click)(&self.checked.inverse(), cx);
|
||||
.on_click(move |_event, window, cx| {
|
||||
(self.on_click)(&self.checked.inverse(), window, cx);
|
||||
})
|
||||
.child(self.label),
|
||||
)
|
||||
|
@ -272,7 +274,7 @@ pub struct Switch {
|
|||
id: ElementId,
|
||||
toggle_state: ToggleState,
|
||||
disabled: bool,
|
||||
on_click: Option<Box<dyn Fn(&ToggleState, &mut WindowContext) + 'static>>,
|
||||
on_click: Option<Box<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>>,
|
||||
label: Option<SharedString>,
|
||||
key_binding: Option<KeyBinding>,
|
||||
}
|
||||
|
@ -299,7 +301,7 @@ impl Switch {
|
|||
/// Binds a handler to the [`Switch`] that will be called when clicked.
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl Fn(&ToggleState, &mut WindowContext) + 'static,
|
||||
handler: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
self.on_click = Some(Box::new(handler));
|
||||
self
|
||||
|
@ -319,7 +321,7 @@ impl Switch {
|
|||
}
|
||||
|
||||
impl RenderOnce for Switch {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let is_on = self.toggle_state == ToggleState::Selected;
|
||||
let adjust_ratio = if is_light(cx) { 1.5 } else { 1.0 };
|
||||
let base_color = cx.theme().colors().text;
|
||||
|
@ -386,7 +388,9 @@ impl RenderOnce for Switch {
|
|||
.when_some(
|
||||
self.on_click.filter(|_| !self.disabled),
|
||||
|this, on_click| {
|
||||
this.on_click(move |_, cx| on_click(&self.toggle_state.inverse(), cx))
|
||||
this.on_click(move |_, window, cx| {
|
||||
on_click(&self.toggle_state.inverse(), window, cx)
|
||||
})
|
||||
},
|
||||
)
|
||||
.when_some(self.label, |this, label| {
|
||||
|
@ -401,7 +405,7 @@ impl ComponentPreview for Checkbox {
|
|||
"A checkbox lets people choose between a pair of opposing states, like enabled and disabled, using a different appearance to indicate each state."
|
||||
}
|
||||
|
||||
fn examples(_: &mut WindowContext) -> Vec<ComponentExampleGroup<Self>> {
|
||||
fn examples(_window: &mut Window, _: &mut App) -> Vec<ComponentExampleGroup<Self>> {
|
||||
vec![
|
||||
example_group_with_title(
|
||||
"Default",
|
||||
|
@ -595,18 +599,18 @@ impl ComponentPreview for Switch {
|
|||
"A switch toggles between two mutually exclusive states, typically used for enabling or disabling a setting."
|
||||
}
|
||||
|
||||
fn examples(_cx: &mut WindowContext) -> Vec<ComponentExampleGroup<Self>> {
|
||||
fn examples(_window: &mut Window, _cx: &mut App) -> Vec<ComponentExampleGroup<Self>> {
|
||||
vec![
|
||||
example_group_with_title(
|
||||
"Default",
|
||||
vec![
|
||||
single_example(
|
||||
"Off",
|
||||
Switch::new("switch_off", ToggleState::Unselected).on_click(|_, _cx| {}),
|
||||
Switch::new("switch_off", ToggleState::Unselected).on_click(|_, _, _cx| {}),
|
||||
),
|
||||
single_example(
|
||||
"On",
|
||||
Switch::new("switch_on", ToggleState::Selected).on_click(|_, _cx| {}),
|
||||
Switch::new("switch_on", ToggleState::Selected).on_click(|_, _, _cx| {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -647,7 +651,7 @@ impl ComponentPreview for CheckboxWithLabel {
|
|||
"A checkbox with an associated label, allowing users to select an option while providing a descriptive text."
|
||||
}
|
||||
|
||||
fn examples(_: &mut WindowContext) -> Vec<ComponentExampleGroup<Self>> {
|
||||
fn examples(_window: &mut Window, _: &mut App) -> Vec<ComponentExampleGroup<Self>> {
|
||||
vec![example_group(vec![
|
||||
single_example(
|
||||
"Unselected",
|
||||
|
@ -655,7 +659,7 @@ impl ComponentPreview for CheckboxWithLabel {
|
|||
"checkbox_with_label_unselected",
|
||||
Label::new("Always save on quit"),
|
||||
ToggleState::Unselected,
|
||||
|_, _| {},
|
||||
|_, _, _| {},
|
||||
),
|
||||
),
|
||||
single_example(
|
||||
|
@ -664,7 +668,7 @@ impl ComponentPreview for CheckboxWithLabel {
|
|||
"checkbox_with_label_indeterminate",
|
||||
Label::new("Always save on quit"),
|
||||
ToggleState::Indeterminate,
|
||||
|_, _| {},
|
||||
|_, _, _| {},
|
||||
),
|
||||
),
|
||||
single_example(
|
||||
|
@ -673,7 +677,7 @@ impl ComponentPreview for CheckboxWithLabel {
|
|||
"checkbox_with_label_selected",
|
||||
Label::new("Always save on quit"),
|
||||
ToggleState::Selected,
|
||||
|_, _| {},
|
||||
|_, _, _| {},
|
||||
),
|
||||
),
|
||||
])]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue