No moar toggleable
This commit is contained in:
@@ -3,29 +3,22 @@ use std::rc::Rc;
|
||||
use gpui::ClickEvent;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{Color, Icon, IconButton, IconSize, ToggleState, Toggleable};
|
||||
use crate::{Color, Icon, IconButton, IconSize};
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct Disclosure {
|
||||
state: ToggleState,
|
||||
is_open: bool,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
impl Disclosure {
|
||||
pub fn new(state: ToggleState) -> Self {
|
||||
pub fn new(is_open: bool) -> Self {
|
||||
Self {
|
||||
state,
|
||||
is_open,
|
||||
on_toggle: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_toggleable(toggleable: Toggleable) -> Option<Self> {
|
||||
match toggleable {
|
||||
Toggleable::Toggleable(state) => Some(Self::new(state)),
|
||||
Toggleable::NotToggleable => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_toggle(
|
||||
mut self,
|
||||
handler: impl Into<Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,
|
||||
@@ -41,9 +34,10 @@ impl RenderOnce for Disclosure {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
IconButton::new(
|
||||
"toggle",
|
||||
match self.state {
|
||||
ToggleState::Toggled => Icon::ChevronDown,
|
||||
ToggleState::NotToggled => Icon::ChevronRight,
|
||||
if self.is_open {
|
||||
Icon::ChevronDown
|
||||
} else {
|
||||
Icon::ChevronRight
|
||||
},
|
||||
)
|
||||
.color(Color::Muted)
|
||||
|
||||
@@ -7,7 +7,7 @@ use gpui::{AnyElement, Div};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{v_stack, Label, ToggleState, Toggleable};
|
||||
use crate::{v_stack, Label};
|
||||
|
||||
pub use list_header::*;
|
||||
pub use list_item::*;
|
||||
@@ -20,7 +20,7 @@ pub struct List {
|
||||
/// Defaults to "No items"
|
||||
empty_message: SharedString,
|
||||
header: Option<ListHeader>,
|
||||
toggle: Toggleable,
|
||||
toggle: Option<bool>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ impl List {
|
||||
Self {
|
||||
empty_message: "No items".into(),
|
||||
header: None,
|
||||
toggle: Toggleable::NotToggleable,
|
||||
toggle: None,
|
||||
children: SmallVec::new(),
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ impl List {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn toggle(mut self, toggle: Toggleable) -> Self {
|
||||
pub fn toggle(mut self, toggle: Option<bool>) -> Self {
|
||||
self.toggle = toggle;
|
||||
self
|
||||
}
|
||||
@@ -66,7 +66,7 @@ impl RenderOnce for List {
|
||||
.children(self.header.map(|header| header))
|
||||
.map(|this| match (self.children.is_empty(), self.toggle) {
|
||||
(false, _) => this.children(self.children),
|
||||
(true, Toggleable::Toggleable(ToggleState::NotToggled)) => this,
|
||||
(true, Some(false)) => this,
|
||||
(true, _) => this.child(Label::new(self.empty_message.clone()).color(Color::Muted)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::rc::Rc;
|
||||
use gpui::{ClickEvent, Div};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{h_stack, Disclosure, Icon, IconButton, IconElement, IconSize, Label, Toggleable};
|
||||
use crate::{h_stack, Disclosure, Icon, IconButton, IconElement, IconSize, Label};
|
||||
|
||||
pub enum ListHeaderMeta {
|
||||
Tools(Vec<IconButton>),
|
||||
@@ -17,7 +17,7 @@ pub struct ListHeader {
|
||||
label: SharedString,
|
||||
left_icon: Option<Icon>,
|
||||
meta: Option<ListHeaderMeta>,
|
||||
toggle: Toggleable,
|
||||
toggle: Option<bool>,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
inset: bool,
|
||||
selected: bool,
|
||||
@@ -30,13 +30,13 @@ impl ListHeader {
|
||||
left_icon: None,
|
||||
meta: None,
|
||||
inset: false,
|
||||
toggle: Toggleable::NotToggleable,
|
||||
toggle: None,
|
||||
on_toggle: None,
|
||||
selected: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle(mut self, toggle: Toggleable) -> Self {
|
||||
pub fn toggle(mut self, toggle: Option<bool>) -> Self {
|
||||
self.toggle = toggle;
|
||||
self
|
||||
}
|
||||
@@ -114,8 +114,8 @@ impl RenderOnce for ListHeader {
|
||||
.child(Label::new(self.label.clone()).color(Color::Muted)),
|
||||
)
|
||||
.children(
|
||||
Disclosure::from_toggleable(self.toggle)
|
||||
.map(|disclosure| disclosure.on_toggle(self.on_toggle)),
|
||||
self.toggle
|
||||
.map(|is_open| Disclosure::new(is_open).on_toggle(self.on_toggle)),
|
||||
),
|
||||
)
|
||||
.child(meta),
|
||||
|
||||
@@ -6,7 +6,7 @@ use gpui::{
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{Avatar, Disclosure, GraphicSlot, Icon, IconElement, IconSize, Toggleable};
|
||||
use crate::{Avatar, Disclosure, GraphicSlot, Icon, IconElement, IconSize};
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct ListItem {
|
||||
@@ -17,7 +17,7 @@ pub struct ListItem {
|
||||
indent_level: usize,
|
||||
indent_step_size: Pixels,
|
||||
left_slot: Option<GraphicSlot>,
|
||||
toggle: Toggleable,
|
||||
toggle: Option<bool>,
|
||||
inset: bool,
|
||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
@@ -33,7 +33,7 @@ impl ListItem {
|
||||
indent_level: 0,
|
||||
indent_step_size: px(12.),
|
||||
left_slot: None,
|
||||
toggle: Toggleable::NotToggleable,
|
||||
toggle: None,
|
||||
inset: false,
|
||||
on_click: None,
|
||||
on_secondary_mouse_down: None,
|
||||
@@ -70,7 +70,7 @@ impl ListItem {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn toggle(mut self, toggle: Toggleable) -> Self {
|
||||
pub fn toggle(mut self, toggle: Option<bool>) -> Self {
|
||||
self.toggle = toggle;
|
||||
self
|
||||
}
|
||||
@@ -151,8 +151,8 @@ impl RenderOnce for ListItem {
|
||||
.items_center()
|
||||
.relative()
|
||||
.children(
|
||||
Disclosure::from_toggleable(self.toggle)
|
||||
.map(|disclosure| disclosure.on_toggle(self.on_toggle)),
|
||||
self.toggle
|
||||
.map(|is_open| Disclosure::new(is_open).on_toggle(self.on_toggle)),
|
||||
)
|
||||
.map(|this| match self.left_slot {
|
||||
Some(GraphicSlot::Icon(i)) => this.child(
|
||||
|
||||
@@ -2,7 +2,7 @@ use gpui::{Div, Render};
|
||||
use story::Story;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{Disclosure, ToggleState};
|
||||
use crate::Disclosure;
|
||||
|
||||
pub struct DisclosureStory;
|
||||
|
||||
@@ -13,8 +13,8 @@ impl Render for DisclosureStory {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Disclosure>())
|
||||
.child(Story::label("Toggled"))
|
||||
.child(Disclosure::new(ToggleState::Toggled))
|
||||
.child(Disclosure::new(true))
|
||||
.child(Story::label("Not Toggled"))
|
||||
.child(Disclosure::new(ToggleState::NotToggled))
|
||||
.child(Disclosure::new(false))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user