Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Rearrange to hopefully make merging easier
Nathan Sobo81b03d379e49
diff --git a/crates/collab_ui2/src/face_pile.rs b/crates/collab_ui2/src/face_pile.rsindex fd675127e4a..1c0d8100d85 100644--- a/crates/collab_ui2/src/face_pile.rs+++ b/crates/collab_ui2/src/face_pile.rs@@ -9,9 +9,9 @@ pub struct FacePile {}impl RenderOnce for FacePile {- type Rendered = Div;+ type Output = Div;- fn render(self, _: &mut WindowContext) -> Self::Rendered {+ fn render(self, _: &mut WindowContext) -> Self::Output {let player_count = self.faces.len();let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {let isnt_last = ix < player_count - 1;diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rsindex eedc5e35b17..cc3dc731157 100644--- a/crates/gpui2/src/element.rs+++ b/crates/gpui2/src/element.rs@@ -6,8 +6,20 @@ use derive_more::{Deref, DerefMut};pub(crate) use smallvec::SmallVec;use std::{any::Any, fmt::Debug};-pub trait Render: 'static + Sized {- fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element;+pub trait Element: 'static + IntoElement {+ type State: 'static;++ fn layout(+ &mut self,+ state: Option<Self::State>,+ cx: &mut WindowContext,+ ) -> (LayoutId, Self::State);++ fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext);++ fn into_any(self) -> AnyElement {+ AnyElement::new(self)+ }}pub trait IntoElement: Sized {@@ -81,35 +93,44 @@ pub trait IntoElement: Sized {}}-pub trait Element: 'static + IntoElement {- type State: 'static;-- fn layout(- &mut self,- state: Option<Self::State>,- cx: &mut WindowContext,- ) -> (LayoutId, Self::State);+pub trait Render: 'static + Sized {+ fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element;+}- fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext);+pub trait RenderOnce: 'static {+ type Output: IntoElement;- fn into_any(self) -> AnyElement {- AnyElement::new(self)- }+ fn render(self, cx: &mut WindowContext) -> Self::Output;}-pub trait RenderOnce: 'static {- type Rendered: IntoElement;+pub trait ParentElement {+ fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>;++ fn child(mut self, child: impl IntoElement) -> Self+ where+ Self: Sized,+ {+ self.children_mut().push(child.into_element().into_any());+ self+ }- fn render(self, cx: &mut WindowContext) -> Self::Rendered;+ fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self+ where+ Self: Sized,+ {+ self.children_mut()+ .extend(children.into_iter().map(|child| child.into_any_element()));+ self+ }}pub struct Component<C> {component: Option<C>,}-pub struct CompositeElementState<C: RenderOnce> {- rendered_element: Option<<C::Rendered as IntoElement>::Element>,- rendered_element_state: Option<<<C::Rendered as IntoElement>::Element as Element>::State>,+pub struct ComponentState<C: RenderOnce> {+ rendered_element: Option<<C::Output as IntoElement>::Element>,+ rendered_element_state: Option<<<C::Output as IntoElement>::Element as Element>::State>,}impl<C> Component<C> {@@ -121,7 +142,7 @@ impl<C> Component<C> {}impl<C: RenderOnce> Element for Component<C> {- type State = CompositeElementState<C>;+ type State = ComponentState<C>;fn layout(&mut self,@@ -132,7 +153,7 @@ impl<C: RenderOnce> Element for Component<C> {if let Some(element_id) = element.element_id() {let layout_id =cx.with_element_state(element_id, |state, cx| element.layout(state, cx));- let state = CompositeElementState {+ let state = ComponentState {rendered_element: Some(element),rendered_element_state: None,};@@ -140,7 +161,7 @@ impl<C: RenderOnce> Element for Component<C> {} else {let (layout_id, state) =element.layout(state.and_then(|s| s.rendered_element_state), cx);- let state = CompositeElementState {+ let state = ComponentState {rendered_element: Some(element),rendered_element_state: Some(state),};@@ -181,27 +202,6 @@ impl<C: RenderOnce> IntoElement for Component<C> {#[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)]pub struct GlobalElementId(SmallVec<[ElementId; 32]>);-pub trait ParentElement {- fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>;-- fn child(mut self, child: impl IntoElement) -> Self- where- Self: Sized,- {- self.children_mut().push(child.into_element().into_any());- self- }-- fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self- where- Self: Sized,- {- self.children_mut()- .extend(children.into_iter().map(|child| child.into_any_element()));- self- }-}-trait ElementObject {fn element_id(&self) -> Option<ElementId>;diff --git a/crates/quick_action_bar2/src/quick_action_bar.rs b/crates/quick_action_bar2/src/quick_action_bar.rsindex 5cbd1f6bcdd..44ca0150e85 100644--- a/crates/quick_action_bar2/src/quick_action_bar.rs+++ b/crates/quick_action_bar2/src/quick_action_bar.rs@@ -136,9 +136,9 @@ impl QuickActionBarButton {}impl RenderOnce for QuickActionBarButton {- type Rendered = IconButton;+ type Output = IconButton;- fn render(self, _: &mut WindowContext) -> Self::Rendered {+ fn render(self, _: &mut WindowContext) -> Self::Output {let tooltip = self.tooltip.clone();let action = self.action.boxed_clone();diff --git a/crates/recent_projects2/src/highlighted_workspace_location.rs b/crates/recent_projects2/src/highlighted_workspace_location.rsindex a4057d2f4bd..2df4409a5fd 100644--- a/crates/recent_projects2/src/highlighted_workspace_location.rs+++ b/crates/recent_projects2/src/highlighted_workspace_location.rs@@ -43,9 +43,9 @@ impl HighlightedText {}impl RenderOnce for HighlightedText {- type Rendered = HighlightedLabel;+ type Output = HighlightedLabel;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {HighlightedLabel::new(self.text, self.highlight_positions)}}diff --git a/crates/story/src/story.rs b/crates/story/src/story.rsindex 3419af95b09..1a3e84c0d91 100644--- a/crates/story/src/story.rs+++ b/crates/story/src/story.rs@@ -74,9 +74,9 @@ impl ParentElement for StoryContainer {}impl RenderOnce for StoryContainer {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {div().size_full().flex()@@ -294,9 +294,9 @@ impl StoryItem {}impl RenderOnce for StoryItem {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {div().my_2().flex()@@ -358,9 +358,9 @@ impl StorySection {}impl RenderOnce for StorySection {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {let children: SmallVec<[AnyElement; 2]> = SmallVec::from_iter(Itertools::intersperse_with(self.children.into_iter(),|| Story::divider().into_any_element(),diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rsindex 73d1abac55c..4ae6279d75e 100644--- a/crates/storybook2/src/stories/z_index.rs+++ b/crates/storybook2/src/stories/z_index.rs@@ -80,9 +80,9 @@ struct ZIndexExample {}impl RenderOnce for ZIndexExample {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {div().relative().size_full()diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rsindex 793872cd8ab..257e46989b6 100644--- a/crates/ui2/src/components/avatar.rs+++ b/crates/ui2/src/components/avatar.rs@@ -16,9 +16,9 @@ pub struct Avatar {}impl RenderOnce for Avatar {- type Rendered = Div;+ type Output = Div;- fn render(mut self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(mut self, cx: &mut WindowContext) -> Self::Output {if self.image.style().corner_radii.top_left.is_none() {self = self.shape(Shape::Circle);}diff --git a/crates/ui2/src/components/button/button.rs b/crates/ui2/src/components/button/button.rsindex bc5d03d639f..2ad12919fba 100644--- a/crates/ui2/src/components/button/button.rs+++ b/crates/ui2/src/components/button/button.rs@@ -136,9 +136,9 @@ impl ButtonCommon for Button {}impl RenderOnce for Button {- type Rendered = ButtonLike;+ type Output = ButtonLike;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {let is_disabled = self.base.disabled;let is_selected = self.base.selected;diff --git a/crates/ui2/src/components/button/button_icon.rs b/crates/ui2/src/components/button/button_icon.rsindex 3b2c703938b..a82aa14e6ed 100644--- a/crates/ui2/src/components/button/button_icon.rs+++ b/crates/ui2/src/components/button/button_icon.rs@@ -63,9 +63,9 @@ impl Selectable for ButtonIcon {}impl RenderOnce for ButtonIcon {- type Rendered = IconElement;+ type Output = IconElement;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {let icon = self.selected_icon.filter(|_| self.selected)diff --git a/crates/ui2/src/components/button/button_like.rs b/crates/ui2/src/components/button/button_like.rsindex 13d4f360f21..0f304ae15d9 100644--- a/crates/ui2/src/components/button/button_like.rs+++ b/crates/ui2/src/components/button/button_like.rs@@ -363,9 +363,9 @@ impl ParentElement for ButtonLike {}impl RenderOnce for ButtonLike {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {self.base.h_flex().id(self.id.clone())diff --git a/crates/ui2/src/components/button/icon_button.rs b/crates/ui2/src/components/button/icon_button.rsindex 3a53bb6cb01..9dcb0c04d49 100644--- a/crates/ui2/src/components/button/icon_button.rs+++ b/crates/ui2/src/components/button/icon_button.rs@@ -106,9 +106,9 @@ impl VisibleOnHover for IconButton {}impl RenderOnce for IconButton {- type Rendered = ButtonLike;+ type Output = ButtonLike;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {let is_disabled = self.base.disabled;let is_selected = self.base.selected;diff --git a/crates/ui2/src/components/button/toggle_button.rs b/crates/ui2/src/components/button/toggle_button.rsindex 4a6ecdeb2fc..7ac642011f9 100644--- a/crates/ui2/src/components/button/toggle_button.rs+++ b/crates/ui2/src/components/button/toggle_button.rs@@ -99,9 +99,9 @@ impl ButtonCommon for ToggleButton {}impl RenderOnce for ToggleButton {- type Rendered = ButtonLike;+ type Output = ButtonLike;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {let is_disabled = self.base.disabled;let is_selected = self.base.selected;diff --git a/crates/ui2/src/components/checkbox.rs b/crates/ui2/src/components/checkbox.rsindex 51e38a38f4f..fd92e969460 100644--- a/crates/ui2/src/components/checkbox.rs+++ b/crates/ui2/src/components/checkbox.rs@@ -19,9 +19,9 @@ pub struct Checkbox {}impl RenderOnce for Checkbox {- type Rendered = gpui::Stateful<Div>;+ type Output = gpui::Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {let group_id = format!("checkbox_group_{:?}", self.id);let icon = match self.checked {diff --git a/crates/ui2/src/components/disclosure.rs b/crates/ui2/src/components/disclosure.rsindex 729023986d2..663fba30ca8 100644--- a/crates/ui2/src/components/disclosure.rs+++ b/crates/ui2/src/components/disclosure.rs@@ -28,9 +28,9 @@ impl Disclosure {}impl RenderOnce for Disclosure {- type Rendered = IconButton;+ type Output = IconButton;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {IconButton::new(self.id,match self.is_open {diff --git a/crates/ui2/src/components/divider.rs b/crates/ui2/src/components/divider.rsindex 20744d6c48e..dd30ce0ec57 100644--- a/crates/ui2/src/components/divider.rs+++ b/crates/ui2/src/components/divider.rs@@ -31,9 +31,9 @@ pub struct Divider {}impl RenderOnce for Divider {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {div().map(|this| match self.direction {DividerDirection::Horizontal => {diff --git a/crates/ui2/src/components/icon.rs b/crates/ui2/src/components/icon.rsindex a168f97a50f..b0eed862505 100644--- a/crates/ui2/src/components/icon.rs+++ b/crates/ui2/src/components/icon.rs@@ -196,9 +196,9 @@ pub struct IconElement {}impl RenderOnce for IconElement {- type Rendered = Svg;+ type Output = Svg;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {svg().size(self.size.rems()).flex_none()diff --git a/crates/ui2/src/components/indicator.rs b/crates/ui2/src/components/indicator.rsindex 4a94650dfc6..f3dc62d20f4 100644--- a/crates/ui2/src/components/indicator.rs+++ b/crates/ui2/src/components/indicator.rs@@ -45,9 +45,9 @@ impl Indicator {}impl RenderOnce for Indicator {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {div().flex_none().map(|this| match self.style {diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rsindex 8314f607fef..f0de9891a7f 100644--- a/crates/ui2/src/components/keybinding.rs+++ b/crates/ui2/src/components/keybinding.rs@@ -11,9 +11,9 @@ pub struct KeyBinding {}impl RenderOnce for KeyBinding {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {h_stack().flex_none().gap_2()@@ -91,9 +91,9 @@ pub struct Key {}impl RenderOnce for Key {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {let single_char = self.key.len() == 1;div()@@ -125,9 +125,9 @@ pub struct KeyIcon {}impl RenderOnce for KeyIcon {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {div().w(rems(14. / 16.)).child(IconElement::new(self.icon).size(IconSize::Small))diff --git a/crates/ui2/src/components/label/highlighted_label.rs b/crates/ui2/src/components/label/highlighted_label.rsindex a7fbb0d8167..08dfbe2391a 100644--- a/crates/ui2/src/components/label/highlighted_label.rs+++ b/crates/ui2/src/components/label/highlighted_label.rs@@ -46,9 +46,9 @@ impl LabelCommon for HighlightedLabel {}impl RenderOnce for HighlightedLabel {- type Rendered = LabelLike;+ type Output = LabelLike;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {let highlight_color = cx.theme().colors().text_accent;let mut highlight_indices = self.highlight_indices.iter().copied().peekable();diff --git a/crates/ui2/src/components/label/label.rs b/crates/ui2/src/components/label/label.rsindex 82723408888..888cd506d78 100644--- a/crates/ui2/src/components/label/label.rs+++ b/crates/ui2/src/components/label/label.rs@@ -40,9 +40,9 @@ impl LabelCommon for Label {}impl RenderOnce for Label {- type Rendered = LabelLike;+ type Output = LabelLike;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {self.base.child(self.label)}}diff --git a/crates/ui2/src/components/label/label_like.rs b/crates/ui2/src/components/label/label_like.rsindex ebfbbecceb6..54e383eb487 100644--- a/crates/ui2/src/components/label/label_like.rs+++ b/crates/ui2/src/components/label/label_like.rs@@ -76,9 +76,9 @@ impl ParentElement for LabelLike {}impl RenderOnce for LabelLike {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {div().when(self.strikethrough, |this| {this.relative().child(diff --git a/crates/ui2/src/components/list/list.rs b/crates/ui2/src/components/list/list.rsindex fdfe256bd6b..23ebd8427c5 100644--- a/crates/ui2/src/components/list/list.rs+++ b/crates/ui2/src/components/list/list.rs@@ -46,9 +46,9 @@ impl ParentElement for List {}impl RenderOnce for List {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {v_stack().w_full().py_1().children(self.header).map(|this| {match (self.children.is_empty(), self.toggle) {(false, _) => this.children(self.children),diff --git a/crates/ui2/src/components/list/list_header.rs b/crates/ui2/src/components/list/list_header.rsindex 0c07867c6d0..9726ed2c2b5 100644--- a/crates/ui2/src/components/list/list_header.rs+++ b/crates/ui2/src/components/list/list_header.rs@@ -76,9 +76,9 @@ impl Selectable for ListHeader {}impl RenderOnce for ListHeader {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {h_stack().id(self.label.clone()).w_full()diff --git a/crates/ui2/src/components/list/list_item.rs b/crates/ui2/src/components/list/list_item.rsindex 6295e2940d3..403c24b8e52 100644--- a/crates/ui2/src/components/list/list_item.rs+++ b/crates/ui2/src/components/list/list_item.rs@@ -147,9 +147,9 @@ impl ParentElement for ListItem {}impl RenderOnce for ListItem {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {h_stack().id(self.id).w_full()diff --git a/crates/ui2/src/components/list/list_separator.rs b/crates/ui2/src/components/list/list_separator.rsindex 346b13ddaa3..d7afb0ed930 100644--- a/crates/ui2/src/components/list/list_separator.rs+++ b/crates/ui2/src/components/list/list_separator.rs@@ -6,9 +6,9 @@ use crate::prelude::*;pub struct ListSeparator;impl RenderOnce for ListSeparator {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {div().h_px().w_full()diff --git a/crates/ui2/src/components/list/list_sub_header.rs b/crates/ui2/src/components/list/list_sub_header.rsindex 07a99dabe5b..9f49587a458 100644--- a/crates/ui2/src/components/list/list_sub_header.rs+++ b/crates/ui2/src/components/list/list_sub_header.rs@@ -26,9 +26,9 @@ impl ListSubHeader {}impl RenderOnce for ListSubHeader {- type Rendered = Div;+ type Output = Div;- fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, _cx: &mut WindowContext) -> Self::Output {h_stack().flex_1().w_full().relative().py_1().child(div().h_6()diff --git a/crates/ui2/src/components/popover.rs b/crates/ui2/src/components/popover.rsindex 91713bc3072..7d888ed3aa4 100644--- a/crates/ui2/src/components/popover.rs+++ b/crates/ui2/src/components/popover.rs@@ -41,9 +41,9 @@ pub struct Popover {}impl RenderOnce for Popover {- type Rendered = Div;+ type Output = Div;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {div().flex().gap_1()diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rsindex eddfab81191..567013ef2bc 100644--- a/crates/ui2/src/components/tab.rs+++ b/crates/ui2/src/components/tab.rs@@ -93,9 +93,9 @@ impl ParentElement for Tab {}impl RenderOnce for Tab {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {let (text_color, tab_bg, _tab_hover_bg, _tab_active_bg) = match self.selected {false => (cx.theme().colors().text_muted,diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rsindex c0d9953196d..f3a654eb473 100644--- a/crates/ui2/src/components/tab_bar.rs+++ b/crates/ui2/src/components/tab_bar.rs@@ -89,9 +89,9 @@ impl ParentElement for TabBar {}impl RenderOnce for TabBar {- type Rendered = Stateful<Div>;+ type Output = Stateful<Div>;- fn render(self, cx: &mut WindowContext) -> Self::Rendered {+ fn render(self, cx: &mut WindowContext) -> Self::Output {const HEIGHT_IN_REMS: f32 = 30. / 16.;div()