ui2: Clean up drains

This commit is contained in:
Marshall Bowers 2023-10-26 15:41:29 +02:00
parent d62c51a4b8
commit 7b4a895ab9
8 changed files with 21 additions and 25 deletions

View file

@ -22,7 +22,7 @@ impl ChatPanel {
self self
} }
fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
div() div()
.id(self.element_id.clone()) .id(self.element_id.clone())
.flex() .flex()
@ -60,7 +60,7 @@ impl ChatPanel {
.flex_col() .flex_col()
.gap_3() .gap_3()
.overflow_y_scroll() .overflow_y_scroll()
.children(self.messages.drain(..)), .children(self.messages),
) )
// Composer // Composer
.child(div().flex().my_2().child(Input::new("Message #design"))), .child(div().flex().my_2().child(Input::new("Message #design"))),

View file

@ -42,7 +42,8 @@ impl ContextMenu {
items: items.into_iter().collect(), items: items.into_iter().collect(),
} }
} }
fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -53,7 +54,7 @@ impl ContextMenu {
.child( .child(
List::new( List::new(
self.items self.items
.drain(..) .into_iter()
.map(ContextMenuItem::to_list_item) .map(ContextMenuItem::to_list_item)
.collect(), .collect(),
) )

View file

@ -471,7 +471,7 @@ impl<S: 'static> ListDetailsEntry<S> {
self self
} }
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let settings = user_settings(cx); let settings = user_settings(cx);
@ -504,14 +504,13 @@ impl<S: 'static> ListDetailsEntry<S> {
.child(Label::new(self.label.clone()).color(label_color)) .child(Label::new(self.label.clone()).color(label_color))
.children( .children(
self.meta self.meta
.take()
.map(|meta| Label::new(meta).color(LabelColor::Muted)), .map(|meta| Label::new(meta).color(LabelColor::Muted)),
) )
.child( .child(
h_stack() h_stack()
.gap_1() .gap_1()
.justify_end() .justify_end()
.children(self.actions.take().unwrap_or_default().into_iter()), .children(self.actions.unwrap_or_default()),
) )
} }
} }
@ -564,13 +563,13 @@ impl<S: 'static> List<S> {
self self
} }
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable); let is_toggled = Toggleable::is_toggled(&self.toggleable);
let list_content = match (self.items.is_empty(), is_toggled) { let list_content = match (self.items.is_empty(), is_toggled) {
(_, false) => div(), (_, false) => div(),
(false, _) => div().children(self.items.drain(..)), (false, _) => div().children(self.items),
(true, _) => { (true, _) => {
div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted)) div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))
} }
@ -578,11 +577,7 @@ impl<S: 'static> List<S> {
v_stack() v_stack()
.py_1() .py_1()
.children( .children(self.header.map(|header| header.toggleable(self.toggleable)))
self.header
.take()
.map(|header| header.toggleable(self.toggleable)),
)
.child(list_content) .child(list_content)
} }
} }

View file

@ -58,7 +58,7 @@ impl<S: 'static> Modal<S> {
.child(div().children(self.title.clone().map(|t| Label::new(t)))) .child(div().children(self.title.clone().map(|t| Label::new(t))))
.child(IconButton::new("close", Icon::Close)), .child(IconButton::new("close", Icon::Close)),
) )
.child(v_stack().p_1().children(self.children.drain(..))) .child(v_stack().p_1().children(self.children))
.when( .when(
self.primary_action.is_some() || self.secondary_action.is_some(), self.primary_action.is_some() || self.secondary_action.is_some(),
|this| { |this| {

View file

@ -42,7 +42,7 @@ impl Palette {
self self
} }
fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -81,7 +81,7 @@ impl Palette {
.into_iter() .into_iter()
.flatten(), .flatten(),
) )
.children(self.items.drain(..).enumerate().map(|(index, item)| { .children(self.items.into_iter().enumerate().map(|(index, item)| {
h_stack() h_stack()
.id(index) .id(index)
.justify_between() .justify_between()

View file

@ -92,7 +92,7 @@ impl<S: 'static> Panel<S> {
self self
} }
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let current_size = self.width.unwrap_or(self.initial_width); let current_size = self.width.unwrap_or(self.initial_width);
@ -113,7 +113,7 @@ impl<S: 'static> Panel<S> {
}) })
.bg(theme.surface) .bg(theme.surface)
.border_color(theme.border) .border_color(theme.border)
.children(self.children.drain(..)) .children(self.children)
} }
} }

View file

@ -96,7 +96,7 @@ impl<V: 'static> PaneGroup<V> {
} }
} }
fn render(mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> { fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx); let theme = theme(cx);
if !self.panes.is_empty() { if !self.panes.is_empty() {
@ -106,7 +106,7 @@ impl<V: 'static> PaneGroup<V> {
.gap_px() .gap_px()
.w_full() .w_full()
.h_full() .h_full()
.children(self.panes.drain(..).map(|pane| pane.render(view, cx))); .children(self.panes.into_iter().map(|pane| pane.render(view, cx)));
if self.split_direction == SplitDirection::Horizontal { if self.split_direction == SplitDirection::Horizontal {
return el; return el;
@ -123,7 +123,7 @@ impl<V: 'static> PaneGroup<V> {
.w_full() .w_full()
.h_full() .h_full()
.bg(theme.editor) .bg(theme.editor)
.children(self.groups.drain(..).map(|group| group.render(view, cx))); .children(self.groups.into_iter().map(|group| group.render(view, cx)));
if self.split_direction == SplitDirection::Horizontal { if self.split_direction == SplitDirection::Horizontal {
return el; return el;

View file

@ -54,7 +54,7 @@ impl<S: 'static> Toolbar<S> {
self self
} }
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -62,8 +62,8 @@ impl<S: 'static> Toolbar<S> {
.p_2() .p_2()
.flex() .flex()
.justify_between() .justify_between()
.child(div().flex().children(self.left_items.drain(..))) .child(div().flex().children(self.left_items))
.child(div().flex().children(self.right_items.drain(..))) .child(div().flex().children(self.right_items))
} }
} }