From 97e6fd295a7dc980b3754b3976ba7bd60e1d800c Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 29 Nov 2023 12:29:48 -0500 Subject: [PATCH 1/2] Remove unneeded wrapping divs in `ListItem` left content --- crates/ui2/src/components/list.rs | 24 ++++++++----------- .../ui2/src/components/stories/list_item.rs | 16 ++++++++++++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index aa61c8333e..f6aa0e08b7 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -265,19 +265,6 @@ impl RenderOnce for ListItem { type Rendered = Stateful
; fn render(self, cx: &mut WindowContext) -> Self::Rendered { - let left_content = match self.left_slot.clone() { - Some(GraphicSlot::Icon(i)) => Some( - h_stack().child( - IconElement::new(i) - .size(IconSize::Small) - .color(Color::Muted), - ), - ), - Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::source(src))), - Some(GraphicSlot::PublicActor(src)) => Some(h_stack().child(Avatar::uri(src))), - None => None, - }; - div() .id(self.id) .relative() @@ -315,7 +302,16 @@ impl RenderOnce for ListItem { .items_center() .relative() .child(disclosure_control(self.toggle, self.on_toggle)) - .children(left_content) + .map(|this| match self.left_slot.clone() { + Some(GraphicSlot::Icon(i)) => this.child( + IconElement::new(i) + .size(IconSize::Small) + .color(Color::Muted), + ), + Some(GraphicSlot::Avatar(src)) => this.child(Avatar::source(src)), + Some(GraphicSlot::PublicActor(src)) => this.child(Avatar::uri(src)), + None => this, + }) .children(self.children), ) } diff --git a/crates/ui2/src/components/stories/list_item.rs b/crates/ui2/src/components/stories/list_item.rs index f6f00007f1..91e95348fd 100644 --- a/crates/ui2/src/components/stories/list_item.rs +++ b/crates/ui2/src/components/stories/list_item.rs @@ -2,7 +2,7 @@ use gpui::{Div, Render}; use story::Story; use crate::prelude::*; -use crate::ListItem; +use crate::{Icon, ListItem}; pub struct ListItemStory; @@ -14,6 +14,20 @@ impl Render for ListItemStory { .child(Story::title_for::()) .child(Story::label("Default")) .child(ListItem::new("hello_world").child("Hello, world!")) + .child(Story::label("With left icon")) + .child( + ListItem::new("with_left_icon") + .child("Hello, world!") + .left_icon(Icon::Bell), + ) + .child(Story::label("With left avatar")) + .child( + ListItem::new("with_left_avatar") + .child("Hello, world!") + .left_avatar(SharedString::from( + "https://avatars.githubusercontent.com/u/1714999?v=4", + )), + ) .child(Story::label("With `on_click`")) .child( ListItem::new("with_on_click") From 912c30c05bd727001f5702dbea85fc3fe6fc7694 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 29 Nov 2023 12:35:39 -0500 Subject: [PATCH 2/2] Remove unneeded `.clone`s --- crates/ui2/src/components/list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index f6aa0e08b7..fbb42b2b4e 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -279,7 +279,7 @@ impl RenderOnce for ListItem { .when(self.selected, |this| { this.bg(cx.theme().colors().ghost_element_selected) }) - .when_some(self.on_click.clone(), |this, on_click| { + .when_some(self.on_click, |this, on_click| { this.cursor_pointer().on_click(move |event, cx| { // HACK: GPUI currently fires `on_click` with any mouse button, // but we only care about the left button. @@ -302,7 +302,7 @@ impl RenderOnce for ListItem { .items_center() .relative() .child(disclosure_control(self.toggle, self.on_toggle)) - .map(|this| match self.left_slot.clone() { + .map(|this| match self.left_slot { Some(GraphicSlot::Icon(i)) => this.child( IconElement::new(i) .size(IconSize::Small)