Use SharedString
for List
s
This commit is contained in:
parent
856d23626f
commit
8dad3ad8ea
3 changed files with 25 additions and 23 deletions
|
@ -3,7 +3,7 @@ use crate::{theme, v_stack, Label, List, ListEntry, ListItem, ListSeparator, Lis
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum ContextMenuItem<S: 'static + Send + Sync + Clone> {
|
pub enum ContextMenuItem<S: 'static + Send + Sync + Clone> {
|
||||||
Header(&'static str),
|
Header(SharedString),
|
||||||
Entry(Label<S>),
|
Entry(Label<S>),
|
||||||
Separator,
|
Separator,
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ impl<S: 'static + Send + Sync + Clone> ContextMenuItem<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header(label: &'static str) -> Self {
|
pub fn header(label: impl Into<SharedString>) -> Self {
|
||||||
Self::Header(label)
|
Self::Header(label.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn separator() -> Self {
|
pub fn separator() -> Self {
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum ListItemVariant {
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element, Clone)]
|
||||||
pub struct ListHeader<S: 'static + Send + Sync + Clone> {
|
pub struct ListHeader<S: 'static + Send + Sync + Clone> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
label: &'static str,
|
label: SharedString,
|
||||||
left_icon: Option<Icon>,
|
left_icon: Option<Icon>,
|
||||||
variant: ListItemVariant,
|
variant: ListItemVariant,
|
||||||
state: InteractionState,
|
state: InteractionState,
|
||||||
|
@ -28,10 +28,10 @@ pub struct ListHeader<S: 'static + Send + Sync + Clone> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
||||||
pub fn new(label: &'static str) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
label,
|
label: label.into(),
|
||||||
left_icon: None,
|
left_icon: None,
|
||||||
variant: ListItemVariant::default(),
|
variant: ListItemVariant::default(),
|
||||||
state: InteractionState::default(),
|
state: InteractionState::default(),
|
||||||
|
@ -131,7 +131,7 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
||||||
.size(IconSize::Small)
|
.size(IconSize::Small)
|
||||||
}))
|
}))
|
||||||
.child(
|
.child(
|
||||||
Label::new(self.label)
|
Label::new(self.label.clone())
|
||||||
.color(LabelColor::Muted)
|
.color(LabelColor::Muted)
|
||||||
.size(LabelSize::Small),
|
.size(LabelSize::Small),
|
||||||
),
|
),
|
||||||
|
@ -144,16 +144,16 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element, Clone)]
|
||||||
pub struct ListSubHeader<S: 'static + Send + Sync + Clone> {
|
pub struct ListSubHeader<S: 'static + Send + Sync + Clone> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
label: &'static str,
|
label: SharedString,
|
||||||
left_icon: Option<Icon>,
|
left_icon: Option<Icon>,
|
||||||
variant: ListItemVariant,
|
variant: ListItemVariant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
|
impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
|
||||||
pub fn new(label: &'static str) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
label,
|
label: label.into(),
|
||||||
left_icon: None,
|
left_icon: None,
|
||||||
variant: ListItemVariant::default(),
|
variant: ListItemVariant::default(),
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
|
||||||
.size(IconSize::Small)
|
.size(IconSize::Small)
|
||||||
}))
|
}))
|
||||||
.child(
|
.child(
|
||||||
Label::new(self.label)
|
Label::new(self.label.clone())
|
||||||
.color(LabelColor::Muted)
|
.color(LabelColor::Muted)
|
||||||
.size(LabelSize::Small),
|
.size(LabelSize::Small),
|
||||||
),
|
),
|
||||||
|
@ -201,7 +201,7 @@ impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum LeftContent {
|
pub enum LeftContent {
|
||||||
Icon(Icon),
|
Icon(Icon),
|
||||||
Avatar(&'static str),
|
Avatar(SharedString),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Copy, Clone)]
|
#[derive(Default, PartialEq, Copy, Clone)]
|
||||||
|
@ -309,8 +309,8 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_left_avatar(mut self, left_avatar: &'static str) -> Self {
|
pub fn set_left_avatar(mut self, left_avatar: impl Into<SharedString>) -> Self {
|
||||||
self.left_content = Some(LeftContent::Avatar(left_avatar));
|
self.left_content = Some(LeftContent::Avatar(left_avatar.into()));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
let system_color = SystemColor::new();
|
let system_color = SystemColor::new();
|
||||||
let color = ThemeColor::new(cx);
|
let color = ThemeColor::new(cx);
|
||||||
|
|
||||||
let left_content = match self.left_content {
|
let left_content = match self.left_content.clone() {
|
||||||
Some(LeftContent::Icon(i)) => Some(
|
Some(LeftContent::Icon(i)) => Some(
|
||||||
h_stack().child(
|
h_stack().child(
|
||||||
IconElement::new(i)
|
IconElement::new(i)
|
||||||
|
@ -452,7 +452,7 @@ impl<S: 'static + Send + Sync> ListSeparator<S> {
|
||||||
#[derive(Element)]
|
#[derive(Element)]
|
||||||
pub struct List<S: 'static + Send + Sync + Clone> {
|
pub struct List<S: 'static + Send + Sync + Clone> {
|
||||||
items: Vec<ListItem<S>>,
|
items: Vec<ListItem<S>>,
|
||||||
empty_message: &'static str,
|
empty_message: SharedString,
|
||||||
header: Option<ListHeader<S>>,
|
header: Option<ListHeader<S>>,
|
||||||
toggleable: Toggleable,
|
toggleable: Toggleable,
|
||||||
}
|
}
|
||||||
|
@ -461,14 +461,14 @@ impl<S: 'static + Send + Sync + Clone> List<S> {
|
||||||
pub fn new(items: Vec<ListItem<S>>) -> Self {
|
pub fn new(items: Vec<ListItem<S>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
items,
|
items,
|
||||||
empty_message: "No items",
|
empty_message: "No items".into(),
|
||||||
header: None,
|
header: None,
|
||||||
toggleable: Toggleable::default(),
|
toggleable: Toggleable::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty_message(mut self, empty_message: &'static str) -> Self {
|
pub fn empty_message(mut self, empty_message: impl Into<SharedString>) -> Self {
|
||||||
self.empty_message = empty_message;
|
self.empty_message = empty_message.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,7 +491,9 @@ impl<S: 'static + Send + Sync + Clone> List<S> {
|
||||||
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.iter().cloned()),
|
(false, _) => div().children(self.items.iter().cloned()),
|
||||||
(true, _) => div().child(Label::new(self.empty_message).color(LabelColor::Muted)),
|
(true, _) => {
|
||||||
|
div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
v_stack()
|
v_stack()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use gpui3::{img, ArcCow};
|
use gpui3::img;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::theme::theme;
|
use crate::theme::theme;
|
||||||
|
@ -8,12 +8,12 @@ use crate::theme::theme;
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element, Clone)]
|
||||||
pub struct Avatar<S: 'static + Send + Sync> {
|
pub struct Avatar<S: 'static + Send + Sync> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
src: ArcCow<'static, str>,
|
src: SharedString,
|
||||||
shape: Shape,
|
shape: Shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync> Avatar<S> {
|
impl<S: 'static + Send + Sync> Avatar<S> {
|
||||||
pub fn new(src: impl Into<ArcCow<'static, str>>) -> Self {
|
pub fn new(src: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
src: src.into(),
|
src: src.into(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue