Remove Clone
bound for Label
This commit is contained in:
parent
d91b423a45
commit
4050bf43c4
3 changed files with 30 additions and 32 deletions
|
@ -1,14 +1,13 @@
|
||||||
use crate::{prelude::*, ListItemVariant};
|
use crate::{prelude::*, ListItemVariant};
|
||||||
use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader};
|
use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader};
|
||||||
|
|
||||||
#[derive(Clone)]
|
pub enum ContextMenuItem<S: 'static + Send + Sync> {
|
||||||
pub enum ContextMenuItem<S: 'static + Send + Sync + Clone> {
|
|
||||||
Header(SharedString),
|
Header(SharedString),
|
||||||
Entry(Label<S>),
|
Entry(Label<S>),
|
||||||
Separator,
|
Separator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ContextMenuItem<S> {
|
impl<S: 'static + Send + Sync> ContextMenuItem<S> {
|
||||||
fn to_list_item(self) -> ListItem<S> {
|
fn to_list_item(self) -> ListItem<S> {
|
||||||
match self {
|
match self {
|
||||||
ContextMenuItem::Header(label) => ListSubHeader::new(label).into(),
|
ContextMenuItem::Header(label) => ListSubHeader::new(label).into(),
|
||||||
|
@ -33,11 +32,11 @@ impl<S: 'static + Send + Sync + Clone> ContextMenuItem<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element)]
|
#[derive(Element)]
|
||||||
pub struct ContextMenu<S: 'static + Send + Sync + Clone> {
|
pub struct ContextMenu<S: 'static + Send + Sync> {
|
||||||
items: Vec<ContextMenuItem<S>>,
|
items: Vec<ContextMenuItem<S>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ContextMenu<S> {
|
impl<S: 'static + Send + Sync> ContextMenu<S> {
|
||||||
pub fn new(items: impl IntoIterator<Item = ContextMenuItem<S>>) -> Self {
|
pub fn new(items: impl IntoIterator<Item = ContextMenuItem<S>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
items: items.into_iter().collect(),
|
items: items.into_iter().collect(),
|
||||||
|
@ -54,8 +53,7 @@ impl<S: 'static + Send + Sync + Clone> ContextMenu<S> {
|
||||||
.child(
|
.child(
|
||||||
List::new(
|
List::new(
|
||||||
self.items
|
self.items
|
||||||
.clone()
|
.drain(..)
|
||||||
.into_iter()
|
|
||||||
.map(ContextMenuItem::to_list_item)
|
.map(ContextMenuItem::to_list_item)
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,8 +14,8 @@ pub enum ListItemVariant {
|
||||||
Inset,
|
Inset,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element)]
|
||||||
pub struct ListHeader<S: 'static + Send + Sync + Clone> {
|
pub struct ListHeader<S: 'static + Send + Sync> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
left_icon: Option<Icon>,
|
left_icon: Option<Icon>,
|
||||||
|
@ -24,7 +24,7 @@ pub struct ListHeader<S: 'static + Send + Sync + Clone> {
|
||||||
toggleable: Toggleable,
|
toggleable: Toggleable,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
impl<S: 'static + Send + Sync> ListHeader<S> {
|
||||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
|
@ -133,15 +133,15 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element)]
|
||||||
pub struct ListSubHeader<S: 'static + Send + Sync + Clone> {
|
pub struct ListSubHeader<S: 'static + Send + Sync> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
label: SharedString,
|
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> ListSubHeader<S> {
|
||||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
|
@ -198,32 +198,32 @@ pub enum ListEntrySize {
|
||||||
Medium,
|
Medium,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Element)]
|
#[derive(Element)]
|
||||||
pub enum ListItem<S: 'static + Send + Sync + Clone> {
|
pub enum ListItem<S: 'static + Send + Sync> {
|
||||||
Entry(ListEntry<S>),
|
Entry(ListEntry<S>),
|
||||||
Separator(ListSeparator<S>),
|
Separator(ListSeparator<S>),
|
||||||
Header(ListSubHeader<S>),
|
Header(ListSubHeader<S>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> From<ListEntry<S>> for ListItem<S> {
|
impl<S: 'static + Send + Sync> From<ListEntry<S>> for ListItem<S> {
|
||||||
fn from(entry: ListEntry<S>) -> Self {
|
fn from(entry: ListEntry<S>) -> Self {
|
||||||
Self::Entry(entry)
|
Self::Entry(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> From<ListSeparator<S>> for ListItem<S> {
|
impl<S: 'static + Send + Sync> From<ListSeparator<S>> for ListItem<S> {
|
||||||
fn from(entry: ListSeparator<S>) -> Self {
|
fn from(entry: ListSeparator<S>) -> Self {
|
||||||
Self::Separator(entry)
|
Self::Separator(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> From<ListSubHeader<S>> for ListItem<S> {
|
impl<S: 'static + Send + Sync> From<ListSubHeader<S>> for ListItem<S> {
|
||||||
fn from(entry: ListSubHeader<S>) -> Self {
|
fn from(entry: ListSubHeader<S>) -> Self {
|
||||||
Self::Header(entry)
|
Self::Header(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ListItem<S> {
|
impl<S: 'static + Send + Sync> ListItem<S> {
|
||||||
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||||
match self {
|
match self {
|
||||||
ListItem::Entry(entry) => div().child(entry.render(view, cx)),
|
ListItem::Entry(entry) => div().child(entry.render(view, cx)),
|
||||||
|
@ -245,11 +245,11 @@ impl<S: 'static + Send + Sync + Clone> ListItem<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element)]
|
||||||
pub struct ListEntry<S: 'static + Send + Sync + Clone> {
|
pub struct ListEntry<S: 'static + Send + Sync> {
|
||||||
disclosure_control_style: DisclosureControlVisibility,
|
disclosure_control_style: DisclosureControlVisibility,
|
||||||
indent_level: u32,
|
indent_level: u32,
|
||||||
label: Label<S>,
|
label: Option<Label<S>>,
|
||||||
left_content: Option<LeftContent>,
|
left_content: Option<LeftContent>,
|
||||||
variant: ListItemVariant,
|
variant: ListItemVariant,
|
||||||
size: ListEntrySize,
|
size: ListEntrySize,
|
||||||
|
@ -257,12 +257,12 @@ pub struct ListEntry<S: 'static + Send + Sync + Clone> {
|
||||||
toggle: Option<ToggleState>,
|
toggle: Option<ToggleState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
impl<S: 'static + Send + Sync> ListEntry<S> {
|
||||||
pub fn new(label: Label<S>) -> Self {
|
pub fn new(label: Label<S>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
disclosure_control_style: DisclosureControlVisibility::default(),
|
disclosure_control_style: DisclosureControlVisibility::default(),
|
||||||
indent_level: 0,
|
indent_level: 0,
|
||||||
label,
|
label: Some(label),
|
||||||
variant: ListItemVariant::default(),
|
variant: ListItemVariant::default(),
|
||||||
left_content: None,
|
left_content: None,
|
||||||
size: ListEntrySize::default(),
|
size: ListEntrySize::default(),
|
||||||
|
@ -411,7 +411,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
.relative()
|
.relative()
|
||||||
.children(self.disclosure_control(cx))
|
.children(self.disclosure_control(cx))
|
||||||
.children(left_content)
|
.children(left_content)
|
||||||
.child(self.label.clone()),
|
.children(self.label.take()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,14 +436,14 @@ 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> {
|
||||||
items: Vec<ListItem<S>>,
|
items: Vec<ListItem<S>>,
|
||||||
empty_message: SharedString,
|
empty_message: SharedString,
|
||||||
header: Option<ListHeader<S>>,
|
header: Option<ListHeader<S>>,
|
||||||
toggleable: Toggleable,
|
toggleable: Toggleable,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> List<S> {
|
impl<S: 'static + Send + Sync> List<S> {
|
||||||
pub fn new(items: Vec<ListItem<S>>) -> Self {
|
pub fn new(items: Vec<ListItem<S>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
items,
|
items,
|
||||||
|
@ -475,7 +475,7 @@ 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.drain(..)),
|
||||||
(true, _) => {
|
(true, _) => {
|
||||||
div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))
|
div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ impl<S: 'static + Send + Sync + Clone> List<S> {
|
||||||
.py_1()
|
.py_1()
|
||||||
.children(
|
.children(
|
||||||
self.header
|
self.header
|
||||||
.clone()
|
.take()
|
||||||
.map(|header| header.set_toggleable(self.toggleable)),
|
.map(|header| header.set_toggleable(self.toggleable)),
|
||||||
)
|
)
|
||||||
.child(list_content)
|
.child(list_content)
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub enum LineHeightStyle {
|
||||||
UILabel,
|
UILabel,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element, Clone)]
|
#[derive(Element)]
|
||||||
pub struct Label<S: 'static + Send + Sync + Clone> {
|
pub struct Label<S: 'static + Send + Sync> {
|
||||||
state_type: PhantomData<S>,
|
state_type: PhantomData<S>,
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
line_height_style: LineHeightStyle,
|
line_height_style: LineHeightStyle,
|
||||||
|
@ -57,7 +57,7 @@ pub struct Label<S: 'static + Send + Sync + Clone> {
|
||||||
strikethrough: bool,
|
strikethrough: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> Label<S> {
|
impl<S: 'static + Send + Sync> Label<S> {
|
||||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue