Avoid PickerStory clone vec.
This commit is contained in:
parent
cab6dc9f6e
commit
310e5e3cde
2 changed files with 14 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
deferred, div, prelude::FluentBuilder as _, px, FocusHandle, FocusableView,
|
deferred, div, prelude::FluentBuilder as _, px, FocusHandle, FocusableView,
|
||||||
InteractiveElement as _, IntoElement, ParentElement, Render, Styled, View, ViewContext,
|
InteractiveElement as _, IntoElement, ParentElement, Render, Styled, View, ViewContext,
|
||||||
|
|
@ -14,8 +16,8 @@ use ui::{
|
||||||
pub struct ListItemDeletegate {
|
pub struct ListItemDeletegate {
|
||||||
story: WeakView<PickerStory>,
|
story: WeakView<PickerStory>,
|
||||||
selected_index: usize,
|
selected_index: usize,
|
||||||
items: Vec<String>,
|
items: Vec<Arc<String>>,
|
||||||
matches: Vec<String>,
|
matches: Vec<Arc<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListDelegate for ListItemDeletegate {
|
impl ListDelegate for ListItemDeletegate {
|
||||||
|
|
@ -47,7 +49,7 @@ impl ListDelegate for ListItemDeletegate {
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.py_1()
|
.py_1()
|
||||||
.px_3()
|
.px_3()
|
||||||
.child(item.clone());
|
.child(item.to_string());
|
||||||
Some(list_item)
|
Some(list_item)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -82,7 +84,7 @@ impl ListDelegate for ListItemDeletegate {
|
||||||
pub struct PickerStory {
|
pub struct PickerStory {
|
||||||
list: View<List<ListItemDeletegate>>,
|
list: View<List<ListItemDeletegate>>,
|
||||||
open: bool,
|
open: bool,
|
||||||
selected_value: Option<String>,
|
selected_value: Option<Arc<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PickerStory {
|
impl PickerStory {
|
||||||
|
|
@ -91,7 +93,7 @@ impl PickerStory {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
let items: Vec<String> = [
|
let items: Vec<Arc<String>> = [
|
||||||
"Baguette (France)",
|
"Baguette (France)",
|
||||||
"Baklava (Turkey)",
|
"Baklava (Turkey)",
|
||||||
"Beef Wellington (UK)",
|
"Beef Wellington (UK)",
|
||||||
|
|
@ -143,7 +145,7 @@ impl PickerStory {
|
||||||
"Wiener Schnitzel (Austria)",
|
"Wiener Schnitzel (Austria)",
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| Arc::new(s.to_string()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let story = cx.view().downgrade();
|
let story = cx.view().downgrade();
|
||||||
|
|
@ -191,10 +193,11 @@ impl Render for PickerStory {
|
||||||
)
|
)
|
||||||
.when_some(self.selected_value.clone(), |this, selected_value| {
|
.when_some(self.selected_value.clone(), |this, selected_value| {
|
||||||
this.child(
|
this.child(
|
||||||
h_flex()
|
h_flex().gap_1().child("You have selected:").child(
|
||||||
.gap_1()
|
div()
|
||||||
.child("You have selected:")
|
.child(selected_value.to_string())
|
||||||
.child(div().child(selected_value).text_color(gpui::red())),
|
.text_color(gpui::red()),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(self.open, |this| {
|
.when(self.open, |this| {
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ impl Render for DraggedTab {
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
Tab::new("", label).selected(self.is_active).render(cx)
|
Tab::new("", label).selected(self.is_active).into_element()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue