Replace derive Element with derive IntoAnyElement everywhere

This commit is contained in:
Nathan Sobo 2023-10-26 12:38:23 +02:00
parent 315744ec20
commit 8ecfea55cd
45 changed files with 185 additions and 292 deletions

View file

@ -4,7 +4,7 @@ use gpui2::img;
use crate::prelude::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Avatar<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
src: SharedString,
@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let mut img = img();
@ -51,7 +51,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct AvatarStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -63,7 +63,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Avatar<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -61,7 +61,7 @@ impl<S: 'static + Send + Sync> Default for ButtonHandlers<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Button<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
disabled: bool,
@ -150,7 +150,7 @@ impl<S: 'static + Send + Sync> Button<S> {
self.icon.map(|i| IconElement::new(i).color(icon_color))
}
pub fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
pub fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let icon_color = self.icon_color();
let mut button = h_stack()
@ -193,7 +193,7 @@ impl<S: 'static + Send + Sync> Button<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ButtonGroup<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
buttons: Vec<Button<S>>,
@ -207,10 +207,10 @@ impl<S: 'static + Send + Sync> ButtonGroup<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let mut el = h_stack().text_size(ui_size(cx, 1.));
for button in &mut self.buttons {
for button in self.buttons {
el = el.child(button.render(_view, cx));
}
@ -230,7 +230,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ButtonStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -242,7 +242,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let states = InteractionState::iter();
Story::container(cx)

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::{prelude::*, v_stack, ButtonGroup};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Details<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
text: &'static str,
@ -30,7 +30,7 @@ impl<S: 'static + Send + Sync> Details<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -54,7 +54,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct DetailsStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -66,7 +66,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Details<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -148,7 +148,7 @@ impl Icon {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct IconElement<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
icon: Icon,
@ -176,7 +176,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let fill = self.color.color(cx);
let svg_size = match self.size {
IconSize::Small => ui_size(cx, 12. / 14.),
@ -202,7 +202,7 @@ mod stories {
use super::*;
#[derive(Element, Default)]
#[derive(IntoAnyElement)]
pub struct IconStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -214,7 +214,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let icons = Icon::iter();
Story::container(cx)

View file

@ -11,7 +11,7 @@ pub enum InputVariant {
Filled,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Input<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
placeholder: SharedString,
@ -60,7 +60,7 @@ impl<S: 'static + Send + Sync> Input<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let (input_bg, input_hover_bg, input_active_bg) = match self.variant {
@ -120,7 +120,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct InputStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -132,7 +132,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -48,7 +48,7 @@ pub enum LineHeightStyle {
UILabel,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Label<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -83,7 +83,7 @@ impl<S: 'static + Send + Sync> Label<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.when(self.strikethrough, |this| {
this.relative().child(
@ -105,7 +105,7 @@ impl<S: 'static + Send + Sync> Label<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct HighlightedLabel<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let highlight_color = theme.text_accent;
@ -211,7 +211,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct LabelStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -223,7 +223,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Label<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ToolDivider<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -14,7 +14,7 @@ impl<S: 'static + Send + Sync> ToolDivider<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div().w_px().h_3().bg(theme.border)