Introduce a Render trait, make views implement it

Don't pass a render function separately from the view.

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Antonio <as-cii@zed.dev>
This commit is contained in:
Max Brunsfeld
2023-10-30 15:19:40 -07:00
co-authored by Nathan Sobo Mikayla Antonio
parent 0128079de0
commit 30dffbb409
49 changed files with 616 additions and 612 deletions
+6 -5
View File
@@ -43,15 +43,16 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::Story;
use super::*;
use crate::Story;
use gpui2::{Div, Render};
#[derive(Component)]
pub struct AvatarStory;
impl AvatarStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for AvatarStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Avatar>(cx))
.child(Story::label(cx, "Default"))
+8 -9
View File
@@ -219,22 +219,21 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use gpui2::rems;
use super::*;
use crate::{h_stack, v_stack, LabelColor, Story};
use gpui2::{rems, Div, Render};
use strum::IntoEnumIterator;
use crate::{h_stack, v_stack, LabelColor, Story};
use super::*;
#[derive(Component)]
pub struct ButtonStory;
impl ButtonStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for ButtonStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let states = InteractionState::iter();
Story::container(cx)
.child(Story::title_for::<_, Button<V>>(cx))
.child(Story::title_for::<_, Button<Self>>(cx))
.child(
div()
.flex()
+7 -6
View File
@@ -46,17 +46,18 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::{Button, Story};
use super::*;
use crate::{Button, Story};
use gpui2::{Div, Render};
#[derive(Component)]
pub struct DetailsStory;
impl DetailsStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for DetailsStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Details<V>>(cx))
.child(Story::title_for::<_, Details<Self>>(cx))
.child(Story::label(cx, "Default"))
.child(Details::new("The quick brown fox jumps over the lazy dog"))
.child(Story::label(cx, "With meta"))
+6 -4
View File
@@ -36,7 +36,7 @@ impl IconColor {
IconColor::Error => gpui2::red(),
IconColor::Warning => gpui2::red(),
IconColor::Success => gpui2::red(),
IconColor::Info => gpui2::red()
IconColor::Info => gpui2::red(),
}
}
}
@@ -191,17 +191,19 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use gpui2::{Div, Render};
use strum::IntoEnumIterator;
use crate::Story;
use super::*;
#[derive(Component)]
pub struct IconStory;
impl IconStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for IconStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let icons = Icon::iter();
Story::container(cx)
+6 -5
View File
@@ -112,15 +112,16 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::Story;
use super::*;
use crate::Story;
use gpui2::{Div, Render};
#[derive(Component)]
pub struct InputStory;
impl InputStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for InputStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Input>(cx))
.child(Story::label(cx, "Default"))
+6 -5
View File
@@ -197,15 +197,16 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::Story;
use super::*;
use crate::Story;
use gpui2::{Div, Render};
#[derive(Component)]
pub struct LabelStory;
impl LabelStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
impl Render for LabelStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Label>(cx))
.child(Story::label(cx, "Default"))