Merge remote-tracking branch 'origin/main' into new-view-new-model-rename

This commit is contained in:
Nathan Sobo 2024-01-01 17:42:12 -07:00
commit 47071605a1
44 changed files with 166 additions and 148 deletions

View file

@ -9,9 +9,9 @@ pub struct FacePile {
} }
impl RenderOnce for 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_count = self.faces.len();
let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| { let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {
let isnt_last = ix < player_count - 1; let isnt_last = ix < player_count - 1;

View file

@ -2757,7 +2757,7 @@ enum Invisible {
impl Element for EditorElement { impl Element for EditorElement {
type State = (); type State = ();
fn layout( fn request_layout(
&mut self, &mut self,
_element_state: Option<Self::State>, _element_state: Option<Self::State>,
cx: &mut gpui::WindowContext, cx: &mut gpui::WindowContext,

View file

@ -6,21 +6,42 @@ use derive_more::{Deref, DerefMut};
pub(crate) use smallvec::SmallVec; pub(crate) use smallvec::SmallVec;
use std::{any::Any, fmt::Debug}; use std::{any::Any, fmt::Debug};
pub trait Render: 'static + Sized { pub trait Element: 'static + IntoElement {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element; type State: 'static;
fn request_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)
}
} }
/// Implemented by any type that can be converted into an element.
pub trait IntoElement: Sized { pub trait IntoElement: Sized {
type Element: Element + 'static; /// The specific type of element into which the implementing type is converted.
type Element: Element;
/// The [ElementId] of self once converted into an [Element].
/// If present, the resulting element's state will be carried across frames.
fn element_id(&self) -> Option<ElementId>; fn element_id(&self) -> Option<ElementId>;
/// Convert self into a type that implements [Element].
fn into_element(self) -> Self::Element; fn into_element(self) -> Self::Element;
/// Convert self into a dynamically-typed [AnyElement].
fn into_any_element(self) -> AnyElement { fn into_any_element(self) -> AnyElement {
self.into_element().into_any() self.into_element().into_any()
} }
/// Convert into an element, then draw in the current window at the given origin.
/// The provided available space is provided to the layout engine to determine the size of the root element.
/// Once the element is drawn, its associated element staet is yielded to the given callback.
fn draw_and_update_state<T, R>( fn draw_and_update_state<T, R>(
self, self,
origin: Point<Pixels>, origin: Point<Pixels>,
@ -52,6 +73,7 @@ pub trait IntoElement: Sized {
} }
} }
/// Convert self to another type by calling the given closure. Useful in rendering code.
fn map<U>(self, f: impl FnOnce(Self) -> U) -> U fn map<U>(self, f: impl FnOnce(Self) -> U) -> U
where where
Self: Sized, Self: Sized,
@ -60,6 +82,7 @@ pub trait IntoElement: Sized {
f(self) f(self)
} }
/// Conditionally chain onto self with the given closure. Useful in rendering code.
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where where
Self: Sized, Self: Sized,
@ -67,6 +90,8 @@ pub trait IntoElement: Sized {
self.map(|this| if condition { then(this) } else { this }) self.map(|this| if condition { then(this) } else { this })
} }
/// Conditionally chain onto self with the given closure if the given option is Some.
/// The contents of the option are provided to the closure.
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
where where
Self: Sized, Self: Sized,
@ -81,35 +106,46 @@ pub trait IntoElement: Sized {
} }
} }
pub trait Element: 'static + IntoElement { pub trait Render: 'static + Sized {
type State: 'static; fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element;
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)
}
} }
/// 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 { pub trait RenderOnce: 'static {
type Rendered: IntoElement; type Output: IntoElement;
fn render(self, cx: &mut WindowContext) -> Self::Rendered; fn render(self, cx: &mut WindowContext) -> Self::Output;
}
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
}
} }
pub struct Component<C> { pub struct Component<C> {
component: Option<C>, component: Option<C>,
} }
pub struct CompositeElementState<C: RenderOnce> { pub struct ComponentState<C: RenderOnce> {
rendered_element: Option<<C::Rendered as IntoElement>::Element>, rendered_element: Option<<C::Output as IntoElement>::Element>,
rendered_element_state: Option<<<C::Rendered as IntoElement>::Element as Element>::State>, rendered_element_state: Option<<<C::Output as IntoElement>::Element as Element>::State>,
} }
impl<C> Component<C> { impl<C> Component<C> {
@ -121,9 +157,9 @@ impl<C> Component<C> {
} }
impl<C: RenderOnce> Element for Component<C> { impl<C: RenderOnce> Element for Component<C> {
type State = CompositeElementState<C>; type State = ComponentState<C>;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -131,16 +167,16 @@ impl<C: RenderOnce> Element for Component<C> {
let mut element = self.component.take().unwrap().render(cx).into_element(); let mut element = self.component.take().unwrap().render(cx).into_element();
if let Some(element_id) = element.element_id() { if let Some(element_id) = element.element_id() {
let layout_id = let layout_id =
cx.with_element_state(element_id, |state, cx| element.layout(state, cx)); cx.with_element_state(element_id, |state, cx| element.request_layout(state, cx));
let state = CompositeElementState { let state = ComponentState {
rendered_element: Some(element), rendered_element: Some(element),
rendered_element_state: None, rendered_element_state: None,
}; };
(layout_id, state) (layout_id, state)
} else { } else {
let (layout_id, state) = let (layout_id, state) =
element.layout(state.and_then(|s| s.rendered_element_state), cx); element.request_layout(state.and_then(|s| s.rendered_element_state), cx);
let state = CompositeElementState { let state = ComponentState {
rendered_element: Some(element), rendered_element: Some(element),
rendered_element_state: Some(state), rendered_element_state: Some(state),
}; };
@ -181,27 +217,6 @@ impl<C: RenderOnce> IntoElement for Component<C> {
#[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)]
pub struct GlobalElementId(SmallVec<[ElementId; 32]>); 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 { trait ElementObject {
fn element_id(&self) -> Option<ElementId>; fn element_id(&self) -> Option<ElementId>;
@ -256,15 +271,18 @@ impl<E: Element> DrawableElement<E> {
self.element.as_ref()?.element_id() self.element.as_ref()?.element_id()
} }
fn layout(&mut self, cx: &mut WindowContext) -> LayoutId { fn request_layout(&mut self, cx: &mut WindowContext) -> LayoutId {
let (layout_id, frame_state) = if let Some(id) = self.element.as_ref().unwrap().element_id() let (layout_id, frame_state) = if let Some(id) = self.element.as_ref().unwrap().element_id()
{ {
let layout_id = cx.with_element_state(id, |element_state, cx| { let layout_id = cx.with_element_state(id, |element_state, cx| {
self.element.as_mut().unwrap().layout(element_state, cx) self.element
.as_mut()
.unwrap()
.request_layout(element_state, cx)
}); });
(layout_id, None) (layout_id, None)
} else { } else {
let (layout_id, frame_state) = self.element.as_mut().unwrap().layout(None, cx); let (layout_id, frame_state) = self.element.as_mut().unwrap().request_layout(None, cx);
(layout_id, Some(frame_state)) (layout_id, Some(frame_state))
}; };
@ -323,7 +341,7 @@ impl<E: Element> DrawableElement<E> {
cx: &mut WindowContext, cx: &mut WindowContext,
) -> Size<Pixels> { ) -> Size<Pixels> {
if matches!(&self.phase, ElementDrawPhase::Start) { if matches!(&self.phase, ElementDrawPhase::Start) {
self.layout(cx); self.request_layout(cx);
} }
let layout_id = match &mut self.phase { let layout_id = match &mut self.phase {
@ -378,7 +396,7 @@ where
} }
fn layout(&mut self, cx: &mut WindowContext) -> LayoutId { fn layout(&mut self, cx: &mut WindowContext) -> LayoutId {
DrawableElement::layout(self.as_mut().unwrap(), cx) DrawableElement::request_layout(self.as_mut().unwrap(), cx)
} }
fn paint(&mut self, cx: &mut WindowContext) { fn paint(&mut self, cx: &mut WindowContext) {
@ -452,7 +470,7 @@ impl AnyElement {
impl Element for AnyElement { impl Element for AnyElement {
type State = (); type State = ();
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -500,7 +518,7 @@ impl IntoElement for () {
impl Element for () { impl Element for () {
type State = (); type State = ();
fn layout( fn request_layout(
&mut self, &mut self,
_state: Option<Self::State>, _state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -29,7 +29,7 @@ impl IntoElement for Canvas {
impl Element for Canvas { impl Element for Canvas {
type State = Style; type State = Style;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -768,7 +768,7 @@ impl ParentElement for Div {
impl Element for Div { impl Element for Div {
type State = DivState; type State = DivState;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -1818,12 +1818,12 @@ where
{ {
type State = E::State; type State = E::State;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
self.element.layout(state, cx) self.element.request_layout(state, cx)
} }
fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) { fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) {
@ -1892,12 +1892,12 @@ where
{ {
type State = E::State; type State = E::State;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
self.element.layout(state, cx) self.element.request_layout(state, cx)
} }
fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) { fn paint(&mut self, bounds: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) {

View file

@ -71,7 +71,7 @@ impl Img {
impl Element for Img { impl Element for Img {
type State = InteractiveElementState; type State = InteractiveElementState;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -302,7 +302,7 @@ pub struct ListOffset {
impl Element for List { impl Element for List {
type State = (); type State = ();
fn layout( fn request_layout(
&mut self, &mut self,
_state: Option<Self::State>, _state: Option<Self::State>,
cx: &mut crate::WindowContext, cx: &mut crate::WindowContext,

View file

@ -60,7 +60,7 @@ impl ParentElement for Overlay {
impl Element for Overlay { impl Element for Overlay {
type State = OverlayState; type State = OverlayState;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -26,7 +26,7 @@ impl Svg {
impl Element for Svg { impl Element for Svg {
type State = InteractiveElementState; type State = InteractiveElementState;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -12,7 +12,7 @@ use util::ResultExt;
impl Element for &'static str { impl Element for &'static str {
type State = TextState; type State = TextState;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -42,7 +42,7 @@ impl IntoElement for &'static str {
impl Element for SharedString { impl Element for SharedString {
type State = TextState; type State = TextState;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -118,7 +118,7 @@ impl StyledText {
impl Element for StyledText { impl Element for StyledText {
type State = TextState; type State = TextState;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -331,7 +331,7 @@ impl InteractiveText {
impl Element for InteractiveText { impl Element for InteractiveText {
type State = InteractiveTextState; type State = InteractiveTextState;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -340,14 +340,14 @@ impl Element for InteractiveText {
mouse_down_index, .. mouse_down_index, ..
}) = state }) = state
{ {
let (layout_id, text_state) = self.text.layout(None, cx); let (layout_id, text_state) = self.text.request_layout(None, cx);
let element_state = InteractiveTextState { let element_state = InteractiveTextState {
text_state, text_state,
mouse_down_index, mouse_down_index,
}; };
(layout_id, element_state) (layout_id, element_state)
} else { } else {
let (layout_id, text_state) = self.text.layout(None, cx); let (layout_id, text_state) = self.text.request_layout(None, cx);
let element_state = InteractiveTextState { let element_state = InteractiveTextState {
text_state, text_state,
mouse_down_index: Rc::default(), mouse_down_index: Rc::default(),

View file

@ -116,7 +116,7 @@ pub struct UniformListState {
impl Element for UniformList { impl Element for UniformList {
type State = UniformListState; type State = UniformListState;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -81,12 +81,12 @@ impl<V: 'static> View<V> {
impl<V: Render> Element for View<V> { impl<V: Render> Element for View<V> {
type State = Option<AnyElement>; type State = Option<AnyElement>;
fn layout( fn request_layout(
&mut self, &mut self,
_state: Option<Self::State>, _state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
let mut element = self.update(cx, |view, cx| view.render(cx).into_any()); let mut element = self.update(cx, |view, cx| view.render(cx).into_any_element());
let layout_id = element.layout(cx); let layout_id = element.layout(cx);
(layout_id, Some(element)) (layout_id, Some(element))
} }
@ -229,7 +229,7 @@ impl<V: Render> From<View<V>> for AnyView {
impl Element for AnyView { impl Element for AnyView {
type State = Option<AnyElement>; type State = Option<AnyElement>;
fn layout( fn request_layout(
&mut self, &mut self,
_state: Option<Self::State>, _state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
@ -313,14 +313,14 @@ impl std::fmt::Debug for AnyWeakView {
} }
mod any_view { mod any_view {
use crate::{AnyElement, AnyView, Element, LayoutId, Render, WindowContext}; use crate::{AnyElement, AnyView, IntoElement, LayoutId, Render, WindowContext};
pub(crate) fn layout<V: 'static + Render>( pub(crate) fn layout<V: 'static + Render>(
view: &AnyView, view: &AnyView,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, AnyElement) { ) -> (LayoutId, AnyElement) {
let view = view.clone().downcast::<V>().unwrap(); let view = view.clone().downcast::<V>().unwrap();
let mut element = view.update(cx, |view, cx| view.render(cx).into_any()); let mut element = view.update(cx, |view, cx| view.render(cx).into_any_element());
let layout_id = element.layout(cx); let layout_id = element.layout(cx);
(layout_id, element) (layout_id, element)
} }

View file

@ -136,9 +136,9 @@ impl QuickActionBarButton {
} }
impl RenderOnce for 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 tooltip = self.tooltip.clone();
let action = self.action.boxed_clone(); let action = self.action.boxed_clone();

View file

@ -43,9 +43,9 @@ impl HighlightedText {
} }
impl RenderOnce for 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) HighlightedLabel::new(self.text, self.highlight_positions)
} }
} }

View file

@ -74,9 +74,9 @@ impl ParentElement for StoryContainer {
} }
impl RenderOnce 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() div()
.size_full() .size_full()
.flex() .flex()
@ -294,9 +294,9 @@ impl StoryItem {
} }
impl RenderOnce for 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() div()
.my_2() .my_2()
.flex() .flex()
@ -358,9 +358,9 @@ impl StorySection {
} }
impl RenderOnce for 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( let children: SmallVec<[AnyElement; 2]> = SmallVec::from_iter(Itertools::intersperse_with(
self.children.into_iter(), self.children.into_iter(),
|| Story::divider().into_any_element(), || Story::divider().into_any_element(),

View file

@ -80,9 +80,9 @@ struct ZIndexExample {
} }
impl RenderOnce for 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() div()
.relative() .relative()
.size_full() .size_full()

View file

@ -750,7 +750,7 @@ impl TerminalElement {
impl Element for TerminalElement { impl Element for TerminalElement {
type State = InteractiveElementState; type State = InteractiveElementState;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext<'_>, cx: &mut WindowContext<'_>,

View file

@ -16,9 +16,9 @@ pub struct Avatar {
} }
impl RenderOnce for 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() { if self.image.style().corner_radii.top_left.is_none() {
self = self.shape(Shape::Circle); self = self.shape(Shape::Circle);
} }

View file

@ -136,9 +136,9 @@ impl ButtonCommon for Button {
} }
impl RenderOnce 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_disabled = self.base.disabled;
let is_selected = self.base.selected; let is_selected = self.base.selected;

View file

@ -63,9 +63,9 @@ impl Selectable for ButtonIcon {
} }
impl RenderOnce 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 let icon = self
.selected_icon .selected_icon
.filter(|_| self.selected) .filter(|_| self.selected)

View file

@ -363,9 +363,9 @@ impl ParentElement for ButtonLike {
} }
impl RenderOnce 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 self.base
.h_flex() .h_flex()
.id(self.id.clone()) .id(self.id.clone())

View file

@ -106,9 +106,9 @@ impl VisibleOnHover for IconButton {
} }
impl RenderOnce 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_disabled = self.base.disabled;
let is_selected = self.base.selected; let is_selected = self.base.selected;

View file

@ -99,9 +99,9 @@ impl ButtonCommon for ToggleButton {
} }
impl RenderOnce 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_disabled = self.base.disabled;
let is_selected = self.base.selected; let is_selected = self.base.selected;

View file

@ -19,9 +19,9 @@ pub struct Checkbox {
} }
impl RenderOnce for 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 group_id = format!("checkbox_group_{:?}", self.id);
let icon = match self.checked { let icon = match self.checked {

View file

@ -28,9 +28,9 @@ impl Disclosure {
} }
impl RenderOnce for 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( IconButton::new(
self.id, self.id,
match self.is_open { match self.is_open {

View file

@ -31,9 +31,9 @@ pub struct Divider {
} }
impl RenderOnce for 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() div()
.map(|this| match self.direction { .map(|this| match self.direction {
DividerDirection::Horizontal => { DividerDirection::Horizontal => {

View file

@ -196,9 +196,9 @@ pub struct IconElement {
} }
impl RenderOnce for 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() svg()
.size(self.size.rems()) .size(self.size.rems())
.flex_none() .flex_none()

View file

@ -45,9 +45,9 @@ impl Indicator {
} }
impl RenderOnce for 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() div()
.flex_none() .flex_none()
.map(|this| match self.style { .map(|this| match self.style {

View file

@ -11,9 +11,9 @@ pub struct KeyBinding {
} }
impl RenderOnce for 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() h_stack()
.flex_none() .flex_none()
.gap_2() .gap_2()
@ -91,9 +91,9 @@ pub struct Key {
} }
impl RenderOnce for 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; let single_char = self.key.len() == 1;
div() div()
@ -125,9 +125,9 @@ pub struct KeyIcon {
} }
impl RenderOnce for 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() div()
.w(rems(14. / 16.)) .w(rems(14. / 16.))
.child(IconElement::new(self.icon).size(IconSize::Small)) .child(IconElement::new(self.icon).size(IconSize::Small))

View file

@ -46,9 +46,9 @@ impl LabelCommon for HighlightedLabel {
} }
impl RenderOnce 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 highlight_color = cx.theme().colors().text_accent;
let mut highlight_indices = self.highlight_indices.iter().copied().peekable(); let mut highlight_indices = self.highlight_indices.iter().copied().peekable();

View file

@ -40,9 +40,9 @@ impl LabelCommon for Label {
} }
impl RenderOnce 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) self.base.child(self.label)
} }
} }

View file

@ -76,9 +76,9 @@ impl ParentElement for LabelLike {
} }
impl RenderOnce 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() div()
.when(self.strikethrough, |this| { .when(self.strikethrough, |this| {
this.relative().child( this.relative().child(

View file

@ -46,9 +46,9 @@ impl ParentElement for List {
} }
impl RenderOnce 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| { v_stack().w_full().py_1().children(self.header).map(|this| {
match (self.children.is_empty(), self.toggle) { match (self.children.is_empty(), self.toggle) {
(false, _) => this.children(self.children), (false, _) => this.children(self.children),

View file

@ -76,9 +76,9 @@ impl Selectable for ListHeader {
} }
impl RenderOnce 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() h_stack()
.id(self.label.clone()) .id(self.label.clone())
.w_full() .w_full()

View file

@ -147,9 +147,9 @@ impl ParentElement for ListItem {
} }
impl RenderOnce 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() h_stack()
.id(self.id) .id(self.id)
.w_full() .w_full()

View file

@ -6,9 +6,9 @@ use crate::prelude::*;
pub struct ListSeparator; pub struct ListSeparator;
impl RenderOnce for 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() div()
.h_px() .h_px()
.w_full() .w_full()

View file

@ -26,9 +26,9 @@ impl ListSubHeader {
} }
impl RenderOnce for 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( h_stack().flex_1().w_full().relative().py_1().child(
div() div()
.h_6() .h_6()

View file

@ -41,9 +41,9 @@ pub struct Popover {
} }
impl RenderOnce for 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() div()
.flex() .flex()
.gap_1() .gap_1()

View file

@ -130,7 +130,7 @@ pub struct PopoverMenuState<M> {
impl<M: ManagedView> Element for PopoverMenu<M> { impl<M: ManagedView> Element for PopoverMenu<M> {
type State = PopoverMenuState<M>; type State = PopoverMenuState<M>;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -60,7 +60,7 @@ pub struct MenuHandleState<M> {
impl<M: ManagedView> Element for RightClickMenu<M> { impl<M: ManagedView> Element for RightClickMenu<M> {
type State = MenuHandleState<M>; type State = MenuHandleState<M>;
fn layout( fn request_layout(
&mut self, &mut self,
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,

View file

@ -93,9 +93,9 @@ impl ParentElement for Tab {
} }
impl RenderOnce 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 { let (text_color, tab_bg, _tab_hover_bg, _tab_active_bg) = match self.selected {
false => ( false => (
cx.theme().colors().text_muted, cx.theme().colors().text_muted,

View file

@ -89,9 +89,9 @@ impl ParentElement for TabBar {
} }
impl RenderOnce 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.; const HEIGHT_IN_REMS: f32 = 30. / 16.;
div() div()

View file

@ -773,7 +773,7 @@ mod element {
impl Element for PaneAxisElement { impl Element for PaneAxisElement {
type State = Rc<RefCell<Option<usize>>>; type State = Rc<RefCell<Option<usize>>>;
fn layout( fn request_layout(
&mut self, &mut self,
state: Option<Self::State>, state: Option<Self::State>,
cx: &mut ui::prelude::WindowContext, cx: &mut ui::prelude::WindowContext,

View file

@ -4283,7 +4283,7 @@ struct DisconnectedOverlay;
impl Element for DisconnectedOverlay { impl Element for DisconnectedOverlay {
type State = AnyElement; type State = AnyElement;
fn layout( fn request_layout(
&mut self, &mut self,
_: Option<Self::State>, _: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,