No moar toggleable
This commit is contained in:
@@ -179,8 +179,8 @@ use project::Fs;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsStore};
|
||||
use ui::{
|
||||
h_stack, v_stack, Avatar, Button, Color, ContextMenu, Icon, IconButton, IconElement, IconSize, Label, List,
|
||||
ListHeader, ListItem, Toggle, Tooltip,
|
||||
h_stack, v_stack, Avatar, Button, Color, ContextMenu, Icon, IconButton, IconElement, IconSize,
|
||||
Label, List, ListHeader, ListItem, Tooltip,
|
||||
};
|
||||
use util::{maybe, ResultExt, TryFutureExt};
|
||||
use workspace::{
|
||||
@@ -2505,7 +2505,7 @@ impl CollabPanel {
|
||||
.when_some(button, |el, button| el.right_button(button))
|
||||
.selected(is_selected)
|
||||
.when(can_collapse, |el| {
|
||||
el.toggle(ui::Toggle::Toggled(is_collapsed)).on_toggle(
|
||||
el.toggle(Some(is_collapsed)).on_toggle(
|
||||
cx.listener(move |this, _, cx| this.toggle_section_expanded(section, cx)),
|
||||
)
|
||||
});
|
||||
@@ -2757,9 +2757,8 @@ impl CollabPanel {
|
||||
.map(|channel| channel.visibility)
|
||||
== Some(proto::ChannelVisibility::Public);
|
||||
let other_selected = self.selected_channel().map(|channel| channel.id) == Some(channel.id);
|
||||
let disclosed = has_children
|
||||
.then(|| !self.collapsed_channels.binary_search(&channel.id).is_ok())
|
||||
.unwrap_or(false);
|
||||
let disclosed =
|
||||
has_children.then(|| !self.collapsed_channels.binary_search(&channel.id).is_ok());
|
||||
|
||||
let has_messages_notification = channel.unseen_message_id.is_some();
|
||||
let has_notes_notification = channel.unseen_note_version.is_some();
|
||||
@@ -2874,11 +2873,7 @@ impl CollabPanel {
|
||||
),
|
||||
),
|
||||
)
|
||||
.toggle(if has_children {
|
||||
Toggle::Toggled(disclosed)
|
||||
} else {
|
||||
Toggle::NotToggleable
|
||||
})
|
||||
.toggle(disclosed)
|
||||
.on_toggle(
|
||||
cx.listener(move |this, _, cx| {
|
||||
this.toggle_channel_collapsed(channel_id, cx)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/// Whether an element is able to be toggled.
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
pub enum Toggleable {
|
||||
Toggleable(ToggleState),
|
||||
NotToggleable,
|
||||
}
|
||||
|
||||
/// The current state of a [`Toggleable`] element.
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
pub enum ToggleState {
|
||||
Toggled,
|
||||
NotToggled,
|
||||
}
|
||||
|
||||
impl ToggleState {
|
||||
/// Returns whether an entry is toggled.
|
||||
pub fn is_toggled(&self) -> bool {
|
||||
match self {
|
||||
ToggleState::Toggled => true,
|
||||
ToggleState::NotToggled => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for ToggleState {
|
||||
fn from(toggled: bool) -> Self {
|
||||
match toggled {
|
||||
true => Self::Toggled,
|
||||
false => Self::NotToggled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ToggleState> for bool {
|
||||
fn from(value: ToggleState) -> Self {
|
||||
value.is_toggled()
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ pub mod prelude;
|
||||
mod selectable;
|
||||
mod styled_ext;
|
||||
mod styles;
|
||||
mod toggleable;
|
||||
pub mod utils;
|
||||
|
||||
pub use clickable::*;
|
||||
@@ -31,4 +30,3 @@ pub use prelude::*;
|
||||
pub use selectable::*;
|
||||
pub use styled_ext::*;
|
||||
pub use styles::*;
|
||||
pub use toggleable::*;
|
||||
|
||||
Reference in New Issue
Block a user