diff --git a/crates/collab_ui2/src/face_pile.rs b/crates/collab_ui2/src/face_pile.rs index 1c0d8100d85cd2eb3adb14fd59ffef8d092ecc0f..55f4efffac5354effa1da2cbc0ee2c05f8e65ad8 100644 --- a/crates/collab_ui2/src/face_pile.rs +++ b/crates/collab_ui2/src/face_pile.rs @@ -1,5 +1,5 @@ use gpui::{ - div, AnyElement, Div, ElementId, IntoElement, ParentElement, RenderOnce, Styled, WindowContext, + div, AnyElement, ElementId, IntoElement, ParentElement, RenderOnce, Styled, WindowContext, }; use smallvec::SmallVec; @@ -9,9 +9,7 @@ pub struct FacePile { } impl RenderOnce for FacePile { - type Output = Div; - - fn render(self, _: &mut WindowContext) -> Self::Output { + fn render(self, _: &mut WindowContext) -> impl IntoElement { 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.rs index 3c310e10ffae8a3f10ceca0bab51a9838264d01e..4ec4ed35505a2d1c90d3e56d5d5fc0b4aea4fc53 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -113,9 +113,7 @@ pub trait Render: 'static + Sized { /// You can derive [IntoElement] on any type that implements this trait. /// It is used to allow views to be expressed in terms of abstract data. pub trait RenderOnce: 'static { - type Output: IntoElement; - - fn render(self, cx: &mut WindowContext) -> Self::Output; + fn render(self, cx: &mut WindowContext) -> impl IntoElement; } pub trait ParentElement { @@ -139,66 +137,29 @@ pub trait ParentElement { } } -pub struct Component { - component: Option, -} - -pub struct ComponentState { - rendered_element: Option<::Element>, - rendered_element_state: Option<<::Element as Element>::State>, -} +pub struct Component(Option); -impl Component { +impl Component { pub fn new(component: C) -> Self { - Component { - component: Some(component), - } + Component(Some(component)) } } impl Element for Component { - type State = ComponentState; + type State = AnyElement; fn request_layout( &mut self, - state: Option, + _: Option, cx: &mut WindowContext, ) -> (LayoutId, Self::State) { - let mut element = self.component.take().unwrap().render(cx).into_element(); - if let Some(element_id) = element.element_id() { - let layout_id = - cx.with_element_state(element_id, |state, cx| element.request_layout(state, cx)); - let state = ComponentState { - rendered_element: Some(element), - rendered_element_state: None, - }; - (layout_id, state) - } else { - let (layout_id, state) = - element.request_layout(state.and_then(|s| s.rendered_element_state), cx); - let state = ComponentState { - rendered_element: Some(element), - rendered_element_state: Some(state), - }; - (layout_id, state) - } + let mut element = self.0.take().unwrap().render(cx).into_any_element(); + let layout_id = element.request_layout(cx); + (layout_id, element) } - fn paint(&mut self, bounds: Bounds, state: &mut Self::State, cx: &mut WindowContext) { - let mut element = state.rendered_element.take().unwrap(); - if let Some(element_id) = element.element_id() { - cx.with_element_state(element_id, |element_state, cx| { - let mut element_state = element_state.unwrap(); - element.paint(bounds, &mut element_state, cx); - ((), element_state) - }); - } else { - element.paint( - bounds, - &mut state.rendered_element_state.as_mut().unwrap(), - cx, - ); - } + fn paint(&mut self, _: Bounds, element: &mut Self::State, cx: &mut WindowContext) { + element.paint(cx) } } @@ -220,7 +181,7 @@ pub struct GlobalElementId(SmallVec<[ElementId; 32]>); trait ElementObject { fn element_id(&self) -> Option; - fn layout(&mut self, cx: &mut WindowContext) -> LayoutId; + fn request_layout(&mut self, cx: &mut WindowContext) -> LayoutId; fn paint(&mut self, cx: &mut WindowContext); @@ -395,7 +356,7 @@ where self.as_ref().unwrap().element_id() } - fn layout(&mut self, cx: &mut WindowContext) -> LayoutId { + fn request_layout(&mut self, cx: &mut WindowContext) -> LayoutId { DrawableElement::request_layout(self.as_mut().unwrap(), cx) } @@ -435,8 +396,8 @@ impl AnyElement { AnyElement(element) } - pub fn layout(&mut self, cx: &mut WindowContext) -> LayoutId { - self.0.layout(cx) + pub fn request_layout(&mut self, cx: &mut WindowContext) -> LayoutId { + self.0.request_layout(cx) } pub fn paint(&mut self, cx: &mut WindowContext) { @@ -475,7 +436,7 @@ impl Element for AnyElement { _: Option, cx: &mut WindowContext, ) -> (LayoutId, Self::State) { - let layout_id = self.layout(cx); + let layout_id = self.request_layout(cx); (layout_id, ()) } diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 512cc56bb204530e2914493f509a4258145f1ba5..fd789f1ac78db0a651599ad6fa272e4f0578bbc7 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -782,7 +782,7 @@ impl Element for Div { child_layout_ids = self .children .iter_mut() - .map(|child| child.layout(cx)) + .map(|child| child.request_layout(cx)) .collect::>(); cx.request_layout(&style, child_layout_ids.iter().copied()) }) diff --git a/crates/gpui2/src/elements/overlay.rs b/crates/gpui2/src/elements/overlay.rs index b5d8b53c7f613f92b966cd0afa025d636394b12e..6ece891708b738df89da0807fb26207f8600537e 100644 --- a/crates/gpui2/src/elements/overlay.rs +++ b/crates/gpui2/src/elements/overlay.rs @@ -68,7 +68,7 @@ impl Element for Overlay { let child_layout_ids = self .children .iter_mut() - .map(|child| child.layout(cx)) + .map(|child| child.request_layout(cx)) .collect::>(); let mut overlay_style = Style::default(); diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index b39445d5417aa40cd8c61f217cf1013e04a53fe1..64959cd1d41aceda70b8cc8caac1638217df87c2 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -87,7 +87,7 @@ impl Element for View { cx: &mut WindowContext, ) -> (LayoutId, Self::State) { let mut element = self.update(cx, |view, cx| view.render(cx).into_any_element()); - let layout_id = element.layout(cx); + let layout_id = element.request_layout(cx); (layout_id, Some(element)) } @@ -321,7 +321,7 @@ mod any_view { ) -> (LayoutId, AnyElement) { let view = view.clone().downcast::().unwrap(); let mut element = view.update(cx, |view, cx| view.render(cx).into_any_element()); - let layout_id = element.layout(cx); + let layout_id = element.request_layout(cx); (layout_id, element) } diff --git a/crates/quick_action_bar2/src/quick_action_bar.rs b/crates/quick_action_bar2/src/quick_action_bar.rs index 85c0b58556d9fdf8a46c56d2307629eb60a2b137..d8c42589d63bea9775145f6efb211d64077d3af0 100644 --- a/crates/quick_action_bar2/src/quick_action_bar.rs +++ b/crates/quick_action_bar2/src/quick_action_bar.rs @@ -136,9 +136,7 @@ impl QuickActionBarButton { } impl RenderOnce for QuickActionBarButton { - type Output = IconButton; - - fn render(self, _: &mut WindowContext) -> Self::Output { + fn render(self, _: &mut WindowContext) -> impl IntoElement { 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.rs index 2df4409a5fdc20b15ef8e14ccd3b56d082fd1745..b31dabe8bd85d48d8f516292850c171dcee66a13 100644 --- a/crates/recent_projects2/src/highlighted_workspace_location.rs +++ b/crates/recent_projects2/src/highlighted_workspace_location.rs @@ -43,9 +43,7 @@ impl HighlightedText { } impl RenderOnce for HighlightedText { - type Output = HighlightedLabel; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { HighlightedLabel::new(self.text, self.highlight_positions) } } diff --git a/crates/story/src/story.rs b/crates/story/src/story.rs index 1a3e84c0d919d91caac5b0d6bc90654510237714..65bebfc423f3812f28a31c6c42d9d6307189fcf2 100644 --- a/crates/story/src/story.rs +++ b/crates/story/src/story.rs @@ -1,6 +1,5 @@ use gpui::{ - div, hsla, prelude::*, px, rems, AnyElement, Div, ElementId, Hsla, SharedString, Stateful, - WindowContext, + div, hsla, prelude::*, px, rems, AnyElement, Div, ElementId, Hsla, SharedString, WindowContext, }; use itertools::Itertools; use smallvec::SmallVec; @@ -74,9 +73,7 @@ impl ParentElement for StoryContainer { } impl RenderOnce for StoryContainer { - type Output = Stateful
; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { div() .size_full() .flex() @@ -294,9 +291,7 @@ impl StoryItem { } impl RenderOnce for StoryItem { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { div() .my_2() .flex() @@ -358,9 +353,7 @@ impl StorySection { } impl RenderOnce for StorySection { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index b18cc4cb57a059d49a7312504aa5af526ace667b..b6e49bfae32b046242e96a5de34d30c3be806b94 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -80,9 +80,7 @@ struct ZIndexExample { } impl RenderOnce for ZIndexExample { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { div() .relative() .size_full() diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index 257e46989b6faf0b615d668aa3d18e3ede8dc83d..b1dba69520c4d02ac735885f69d84db5d653236b 100644 --- a/crates/ui2/src/components/avatar.rs +++ b/crates/ui2/src/components/avatar.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use gpui::{img, Div, Hsla, ImageSource, Img, IntoElement, Styled}; +use gpui::{img, Hsla, ImageSource, Img, IntoElement, Styled}; #[derive(Debug, Default, PartialEq, Clone)] pub enum Shape { @@ -16,9 +16,7 @@ pub struct Avatar { } impl RenderOnce for Avatar { - type Output = Div; - - fn render(mut self, cx: &mut WindowContext) -> Self::Output { + fn render(mut self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 2ad12919fba8a0daf31b3c7d54d0032ee5777e1b..d46273fb916d380eda66df9a4bb41fd951661f24 100644 --- a/crates/ui2/src/components/button/button.rs +++ b/crates/ui2/src/components/button/button.rs @@ -136,9 +136,8 @@ impl ButtonCommon for Button { } impl RenderOnce for Button { - type Output = ButtonLike; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + #[allow(refining_impl_trait)] + fn render(self, _cx: &mut WindowContext) -> ButtonLike { 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.rs index a82aa14e6ed249d6615c01d6d4567510afdf9d9f..29b23747b22eed50a112ba2a378b9620c4021443 100644 --- a/crates/ui2/src/components/button/button_icon.rs +++ b/crates/ui2/src/components/button/button_icon.rs @@ -63,9 +63,7 @@ impl Selectable for ButtonIcon { } impl RenderOnce for ButtonIcon { - type Output = IconElement; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index 0f304ae15d970172825a0ae7f487da7b3ac555b1..f255104432816f090aad741fdcb5800d589ff74b 100644 --- a/crates/ui2/src/components/button/button_like.rs +++ b/crates/ui2/src/components/button/button_like.rs @@ -1,5 +1,5 @@ use gpui::{relative, DefiniteLength, MouseButton}; -use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful}; +use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Hsla, Rems}; use smallvec::SmallVec; use crate::prelude::*; @@ -363,9 +363,7 @@ impl ParentElement for ButtonLike { } impl RenderOnce for ButtonLike { - type Output = Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 9dcb0c04d49f671331a2f0f8d0e1ed7620d98626..0a75f361cfe10eae59c7da0d0540cac46c81e9c8 100644 --- a/crates/ui2/src/components/button/icon_button.rs +++ b/crates/ui2/src/components/button/icon_button.rs @@ -106,9 +106,7 @@ impl VisibleOnHover for IconButton { } impl RenderOnce for IconButton { - type Output = ButtonLike; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index 7ac642011f97299dabbd483abf0ed49f41a02ead..f97498b0d837539f7a46a9def47e8040d8a429dc 100644 --- a/crates/ui2/src/components/button/toggle_button.rs +++ b/crates/ui2/src/components/button/toggle_button.rs @@ -99,9 +99,7 @@ impl ButtonCommon for ToggleButton { } impl RenderOnce for ToggleButton { - type Output = ButtonLike; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index fd92e9694608da5e273f32f262e55bd7b771b220..a793b8ca10f1e1b791052e5b8807db2e02874ffc 100644 --- a/crates/ui2/src/components/checkbox.rs +++ b/crates/ui2/src/components/checkbox.rs @@ -1,4 +1,4 @@ -use gpui::{div, prelude::*, Div, Element, ElementId, IntoElement, Styled, WindowContext}; +use gpui::{div, prelude::*, Element, ElementId, IntoElement, Styled, WindowContext}; use crate::prelude::*; use crate::{Color, Icon, IconElement, Selection}; @@ -19,9 +19,7 @@ pub struct Checkbox { } impl RenderOnce for Checkbox { - type Output = gpui::Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 663fba30ca873536319f08680dcacaf9ba0bd7e7..d4349f61a0f53b7f70af3255576aaa4c715796ae 100644 --- a/crates/ui2/src/components/disclosure.rs +++ b/crates/ui2/src/components/disclosure.rs @@ -28,9 +28,7 @@ impl Disclosure { } impl RenderOnce for Disclosure { - type Output = IconButton; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { IconButton::new( self.id, match self.is_open { diff --git a/crates/ui2/src/components/divider.rs b/crates/ui2/src/components/divider.rs index dd30ce0ec57e60f78d37b764656c8507ca7bb242..2567c3fc3476c72819f0d30f5eae2a3e74f68059 100644 --- a/crates/ui2/src/components/divider.rs +++ b/crates/ui2/src/components/divider.rs @@ -1,4 +1,4 @@ -use gpui::{Div, Hsla, IntoElement}; +use gpui::{Hsla, IntoElement}; use crate::prelude::*; @@ -31,9 +31,7 @@ pub struct Divider { } impl RenderOnce for Divider { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { div() .map(|this| match self.direction { DividerDirection::Horizontal => { diff --git a/crates/ui2/src/components/icon.rs b/crates/ui2/src/components/icon.rs index 0c618f291528f8f41bc6f22f428322ad1c67f20b..df1c82bb666d2a20084387f80a5896f73266d598 100644 --- a/crates/ui2/src/components/icon.rs +++ b/crates/ui2/src/components/icon.rs @@ -1,4 +1,4 @@ -use gpui::{rems, svg, IntoElement, Rems, Svg}; +use gpui::{rems, svg, IntoElement, Rems}; use strum::EnumIter; use crate::prelude::*; @@ -200,9 +200,7 @@ pub struct IconElement { } impl RenderOnce for IconElement { - type Output = Svg; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { svg() .size(self.size.rems()) .flex_none() diff --git a/crates/ui2/src/components/indicator.rs b/crates/ui2/src/components/indicator.rs index f3dc62d20f4d8b057320d74aa49e182d0869e7f9..97d38b1f22face4b38e97de9cf783206d3749e19 100644 --- a/crates/ui2/src/components/indicator.rs +++ b/crates/ui2/src/components/indicator.rs @@ -1,4 +1,4 @@ -use gpui::{Div, Position}; +use gpui::Position; use crate::prelude::*; @@ -45,9 +45,7 @@ impl Indicator { } impl RenderOnce for Indicator { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { div() .flex_none() .map(|this| match self.style { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 6f6388548971baf317e1b9b287178c1dac7ebf7d..a07ce1116cebc9cf5bfb2be9a0c8948196be3e02 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -1,5 +1,5 @@ use crate::{h_stack, prelude::*, Icon, IconElement, IconSize}; -use gpui::{relative, rems, Action, Div, FocusHandle, IntoElement, Keystroke}; +use gpui::{relative, rems, Action, FocusHandle, IntoElement, Keystroke}; #[derive(IntoElement, Clone)] pub struct KeyBinding { @@ -11,9 +11,7 @@ pub struct KeyBinding { } impl RenderOnce for KeyBinding { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { h_stack() .flex_none() .gap_2() @@ -87,9 +85,7 @@ pub struct Key { } impl RenderOnce for Key { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { let single_char = self.key.len() == 1; div() @@ -121,9 +117,7 @@ pub struct KeyIcon { } impl RenderOnce for KeyIcon { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index 08dfbe2391a270e9a019d8df59d9ececc413cd8c..d70c2d1b51c82e426a508fb413a35d4f4b9e3a70 100644 --- a/crates/ui2/src/components/label/highlighted_label.rs +++ b/crates/ui2/src/components/label/highlighted_label.rs @@ -46,9 +46,7 @@ impl LabelCommon for HighlightedLabel { } impl RenderOnce for HighlightedLabel { - type Output = LabelLike; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 888cd506d78d77ec2314b31ca48c28f0c288a7af..61f463a531b85dc9a2780a334c8a771ab5c9f40b 100644 --- a/crates/ui2/src/components/label/label.rs +++ b/crates/ui2/src/components/label/label.rs @@ -40,9 +40,7 @@ impl LabelCommon for Label { } impl RenderOnce for Label { - type Output = LabelLike; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { self.base.child(self.label) } } diff --git a/crates/ui2/src/components/label/label_like.rs b/crates/ui2/src/components/label/label_like.rs index 54e383eb487e274140eb433b18c560f21f5daa20..436461fddeaffa9b6d87af0de11b11f48cafec68 100644 --- a/crates/ui2/src/components/label/label_like.rs +++ b/crates/ui2/src/components/label/label_like.rs @@ -1,4 +1,4 @@ -use gpui::{relative, AnyElement, Div, Styled}; +use gpui::{relative, AnyElement, Styled}; use smallvec::SmallVec; use crate::prelude::*; @@ -76,9 +76,7 @@ impl ParentElement for LabelLike { } impl RenderOnce for LabelLike { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 23ebd8427c55932f6df6ad8e0a2b79fbac708096..8c657fdd92a4d35891e2cdae30193ac147741907 100644 --- a/crates/ui2/src/components/list/list.rs +++ b/crates/ui2/src/components/list/list.rs @@ -1,4 +1,4 @@ -use gpui::{AnyElement, Div}; +use gpui::AnyElement; use smallvec::SmallVec; use crate::{prelude::*, v_stack, Label, ListHeader}; @@ -46,9 +46,7 @@ impl ParentElement for List { } impl RenderOnce for List { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index 9726ed2c2b524f999a9f178237faff51e8164866..1bed11601512348c7227b7e048468946145ffe41 100644 --- a/crates/ui2/src/components/list/list_header.rs +++ b/crates/ui2/src/components/list/list_header.rs @@ -1,6 +1,5 @@ -use gpui::{AnyElement, ClickEvent, Div, Stateful}; - use crate::{h_stack, prelude::*, Disclosure, Label}; +use gpui::{AnyElement, ClickEvent}; #[derive(IntoElement)] pub struct ListHeader { @@ -76,9 +75,7 @@ impl Selectable for ListHeader { } impl RenderOnce for ListHeader { - type Output = Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 403c24b8e52344ac53b295cc10ac9811e3150313..b4235676fa434de6444dc20ff582255c9584f5d4 100644 --- a/crates/ui2/src/components/list/list_item.rs +++ b/crates/ui2/src/components/list/list_item.rs @@ -1,6 +1,4 @@ -use gpui::{ - px, AnyElement, AnyView, ClickEvent, Div, MouseButton, MouseDownEvent, Pixels, Stateful, -}; +use gpui::{px, AnyElement, AnyView, ClickEvent, MouseButton, MouseDownEvent, Pixels}; use smallvec::SmallVec; use crate::{prelude::*, Disclosure}; @@ -147,9 +145,7 @@ impl ParentElement for ListItem { } impl RenderOnce for ListItem { - type Output = Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index d7afb0ed930e260a8dba20cefd584e44b56a1593..59b85be5ce4a149ac9b3793cd029f8d420575f7b 100644 --- a/crates/ui2/src/components/list/list_separator.rs +++ b/crates/ui2/src/components/list/list_separator.rs @@ -1,14 +1,10 @@ -use gpui::Div; - use crate::prelude::*; #[derive(IntoElement)] pub struct ListSeparator; impl RenderOnce for ListSeparator { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { 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.rs index 9f49587a458eba5c8668bad17771609bbd7a493f..2e976b35178a2132cf1f0a6f2c154f03de249389 100644 --- a/crates/ui2/src/components/list/list_sub_header.rs +++ b/crates/ui2/src/components/list/list_sub_header.rs @@ -1,5 +1,3 @@ -use gpui::Div; - use crate::prelude::*; use crate::{h_stack, Icon, IconElement, IconSize, Label}; @@ -26,9 +24,7 @@ impl ListSubHeader { } impl RenderOnce for ListSubHeader { - type Output = Div; - - fn render(self, _cx: &mut WindowContext) -> Self::Output { + fn render(self, _cx: &mut WindowContext) -> impl IntoElement { 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.rs index 7d888ed3aa4f17dd68a14932102facbc606f0cca..e6fb8874449ec74db4d5d7dac605ec2821a966c2 100644 --- a/crates/ui2/src/components/popover.rs +++ b/crates/ui2/src/components/popover.rs @@ -1,5 +1,5 @@ use gpui::{ - div, AnyElement, Div, Element, ElementId, IntoElement, ParentElement, RenderOnce, Styled, + div, AnyElement, Element, ElementId, IntoElement, ParentElement, RenderOnce, Styled, WindowContext, }; use smallvec::SmallVec; @@ -41,9 +41,7 @@ pub struct Popover { } impl RenderOnce for Popover { - type Output = Div; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { div() .flex() .gap_1() diff --git a/crates/ui2/src/components/popover_menu.rs b/crates/ui2/src/components/popover_menu.rs index 3cc925e0b5f0db95cb04553fc330d82a124a4833..fb823b05dba3d18cea7992948abb50f827167e1c 100644 --- a/crates/ui2/src/components/popover_menu.rs +++ b/crates/ui2/src/components/popover_menu.rs @@ -153,7 +153,7 @@ impl Element for PopoverMenu { } let mut element = overlay.child(menu.clone()).into_any(); - menu_layout_id = Some(element.layout(cx)); + menu_layout_id = Some(element.request_layout(cx)); element }); @@ -164,7 +164,7 @@ impl Element for PopoverMenu { let child_layout_id = child_element .as_mut() - .map(|child_element| child_element.layout(cx)); + .map(|child_element| child_element.request_layout(cx)); let layout_id = cx.request_layout( &gpui::Style::default(), diff --git a/crates/ui2/src/components/right_click_menu.rs b/crates/ui2/src/components/right_click_menu.rs index 81f553a6a2cb2c2fdef829098e5ee5047358fb05..8bf40f61a8264ec3b00eec3ec844efa247876da7 100644 --- a/crates/ui2/src/components/right_click_menu.rs +++ b/crates/ui2/src/components/right_click_menu.rs @@ -81,7 +81,7 @@ impl Element for RightClickMenu { overlay = overlay.position(*position.borrow()); let mut element = overlay.child(menu.clone()).into_any(); - menu_layout_id = Some(element.layout(cx)); + menu_layout_id = Some(element.request_layout(cx)); element }); @@ -92,7 +92,7 @@ impl Element for RightClickMenu { let child_layout_id = child_element .as_mut() - .map(|child_element| child_element.layout(cx)); + .map(|child_element| child_element.request_layout(cx)); let layout_id = cx.request_layout( &gpui::Style::default(), diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 567013ef2bca07c211f9341c652374ebf99021b7..9bafb0c0bba7c8219c729b5b3e15830355710fdf 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -93,9 +93,8 @@ impl ParentElement for Tab { } impl RenderOnce for Tab { - type Output = Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + #[allow(refining_impl_trait)] + fn render(self, cx: &mut WindowContext) -> Stateful
{ 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.rs index f3a654eb4736067f4269f3bd1ad94e7090a4efa6..0a86f1ae0ce52713bde0761340a86c6d8676a0ec 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -1,4 +1,4 @@ -use gpui::{AnyElement, ScrollHandle, Stateful}; +use gpui::{AnyElement, ScrollHandle}; use smallvec::SmallVec; use crate::prelude::*; @@ -89,9 +89,7 @@ impl ParentElement for TabBar { } impl RenderOnce for TabBar { - type Output = Stateful
; - - fn render(self, cx: &mut WindowContext) -> Self::Output { + fn render(self, cx: &mut WindowContext) -> impl IntoElement { const HEIGHT_IN_REMS: f32 = 30. / 16.; div() diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index f5da419c6b4fbee2b04c6ae74ea1541c1110efc7..76715f69bef9ffb5e7f4ced25d00372df897b7e5 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -4305,7 +4305,7 @@ impl Element for DisconnectedOverlay { "Your connection to the remote project has been lost.", )) .into_any(); - (overlay.layout(cx), overlay) + (overlay.request_layout(cx), overlay) } fn paint(&mut self, bounds: Bounds, overlay: &mut Self::State, cx: &mut WindowContext) {