From df5de47a7866e94cbfff391dd086c31773a432f0 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 29 Nov 2023 16:13:41 -0500 Subject: [PATCH] Make `toggle` method accept `impl Into>` (#3446) This PR makes the `toggle` method on the various list components accept an `impl Into>` instead of just an `Option`. This allows a caller with just a `bool` avoid having to wrap the `Option` themselves. Release Notes: - N/A --- crates/collab_ui2/src/collab_panel.rs | 2 +- crates/ui2/src/components/disclosure.rs | 7 +++---- crates/ui2/src/components/list.rs | 4 ++-- crates/ui2/src/components/list/list_header.rs | 4 ++-- crates/ui2/src/components/list/list_item.rs | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/collab_ui2/src/collab_panel.rs b/crates/collab_ui2/src/collab_panel.rs index 62a4dffbfd2ba772ccca5d85a153e044d4692477..3f99fea3156dc83e2e3ae194a8417d31291a514b 100644 --- a/crates/collab_ui2/src/collab_panel.rs +++ b/crates/collab_ui2/src/collab_panel.rs @@ -2505,7 +2505,7 @@ impl CollabPanel { .when_some(button, |el, button| el.right_button(button)) .selected(is_selected) .when(can_collapse, |el| { - el.toggle(Some(is_collapsed)).on_toggle( + el.toggle(is_collapsed).on_toggle( cx.listener(move |this, _, cx| this.toggle_section_expanded(section, cx)), ) }); diff --git a/crates/ui2/src/components/disclosure.rs b/crates/ui2/src/components/disclosure.rs index b3736f36a004a2d63bc8613913ad8ae720e47df9..103c3112dfaa56bb6319735dc64beafd50222193 100644 --- a/crates/ui2/src/components/disclosure.rs +++ b/crates/ui2/src/components/disclosure.rs @@ -34,10 +34,9 @@ impl RenderOnce for Disclosure { fn render(self, _cx: &mut WindowContext) -> Self::Rendered { IconButton::new( "toggle", - if self.is_open { - Icon::ChevronDown - } else { - Icon::ChevronRight + match self.is_open { + true => Icon::ChevronDown, + false => Icon::ChevronRight, }, ) .color(Color::Muted) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index f5eb2eb44bf6ef2ff17a161af025cc503f331fe9..aafd04539149a703ab48e35fe8401f3b7db81f18 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -44,8 +44,8 @@ impl List { self } - pub fn toggle(mut self, toggle: Option) -> Self { - self.toggle = toggle; + pub fn toggle(mut self, toggle: impl Into>) -> Self { + self.toggle = toggle.into(); self } } diff --git a/crates/ui2/src/components/list/list_header.rs b/crates/ui2/src/components/list/list_header.rs index a205de62206939dc3954560b59c1aed0d86a4207..7eacaef920f9bf07afe7741d112186ee63837740 100644 --- a/crates/ui2/src/components/list/list_header.rs +++ b/crates/ui2/src/components/list/list_header.rs @@ -36,8 +36,8 @@ impl ListHeader { } } - pub fn toggle(mut self, toggle: Option) -> Self { - self.toggle = toggle; + pub fn toggle(mut self, toggle: impl Into>) -> Self { + self.toggle = toggle.into(); self } diff --git a/crates/ui2/src/components/list/list_item.rs b/crates/ui2/src/components/list/list_item.rs index d8630289a79ea6f54ae501722344135df4c077a8..34a9844eaf4f53fd61edcc6be625740d8b9b26d6 100644 --- a/crates/ui2/src/components/list/list_item.rs +++ b/crates/ui2/src/components/list/list_item.rs @@ -70,8 +70,8 @@ impl ListItem { self } - pub fn toggle(mut self, toggle: Option) -> Self { - self.toggle = toggle; + pub fn toggle(mut self, toggle: impl Into>) -> Self { + self.toggle = toggle.into(); self }