diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 8cfb69991685aba6424d5974539d73a108976e2f..4ed99d295f5bcd9b659080e06867943a769b73bd 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -8,8 +8,8 @@ use crate::{h_stack, v_stack, Keybinding, Label, LabelColor}; pub struct Palette { state_type: PhantomData, scroll_state: ScrollState, - input_placeholder: &'static str, - empty_string: &'static str, + input_placeholder: SharedString, + empty_string: SharedString, items: Vec>, default_order: OrderMethod, } @@ -19,8 +19,8 @@ impl Palette { Self { state_type: PhantomData, scroll_state, - input_placeholder: "Find something...", - empty_string: "No items found.", + input_placeholder: "Find something...".into(), + empty_string: "No items found.".into(), items: vec![], default_order: OrderMethod::default(), } @@ -31,13 +31,13 @@ impl Palette { self } - pub fn placeholder(mut self, input_placeholder: &'static str) -> Self { - self.input_placeholder = input_placeholder; + pub fn placeholder(mut self, input_placeholder: impl Into) -> Self { + self.input_placeholder = input_placeholder.into(); self } - pub fn empty_string(mut self, empty_string: &'static str) -> Self { - self.empty_string = empty_string; + pub fn empty_string(mut self, empty_string: impl Into) -> Self { + self.empty_string = empty_string.into(); self } @@ -59,11 +59,9 @@ impl Palette { .child( v_stack() .gap_px() - .child(v_stack().py_0p5().px_1().child( - div().px_2().py_0p5().child( - Label::new(self.input_placeholder).color(LabelColor::Placeholder), - ), - )) + .child(v_stack().py_0p5().px_1().child(div().px_2().py_0p5().child( + Label::new(self.input_placeholder.clone()).color(LabelColor::Placeholder), + ))) .child(div().h_px().w_full().bg(theme.lowest.base.default.border)) .child( v_stack() @@ -74,9 +72,12 @@ impl Palette { .overflow_y_scroll(self.scroll_state.clone()) .children( vec![if self.items.is_empty() { - Some(h_stack().justify_between().px_2().py_1().child( - Label::new(self.empty_string).color(LabelColor::Muted), - )) + Some( + h_stack().justify_between().px_2().py_1().child( + Label::new(self.empty_string.clone()) + .color(LabelColor::Muted), + ), + ) } else { None }] @@ -101,26 +102,26 @@ impl Palette { #[derive(Element, Clone)] pub struct PaletteItem { - pub label: &'static str, - pub sublabel: Option<&'static str>, + pub label: SharedString, + pub sublabel: Option, pub keybinding: Option>, } impl PaletteItem { - pub fn new(label: &'static str) -> Self { + pub fn new(label: impl Into) -> Self { Self { - label, + label: label.into(), sublabel: None, keybinding: None, } } - pub fn label(mut self, label: &'static str) -> Self { - self.label = label; + pub fn label(mut self, label: impl Into) -> Self { + self.label = label.into(); self } - pub fn sublabel>>(mut self, sublabel: L) -> Self { + pub fn sublabel(mut self, sublabel: impl Into>) -> Self { self.sublabel = sublabel.into(); self } @@ -143,8 +144,8 @@ impl PaletteItem { .justify_between() .child( v_stack() - .child(Label::new(self.label)) - .children(self.sublabel.map(|sublabel| Label::new(sublabel))), + .child(Label::new(self.label.clone())) + .children(self.sublabel.clone().map(|sublabel| Label::new(sublabel))), ) .children(self.keybinding.clone()) } diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index c38337c57cdc9469b6e02cfbabbaa4e332a01caf..a7d03f975f301161c3f6639d0c75bdc1c8574d46 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -21,12 +21,12 @@ impl RecentProjects { div().child( Palette::new(self.scroll_state.clone()) .items(vec![ - PaletteItem::new("zed").sublabel("~/projects/zed"), - PaletteItem::new("saga").sublabel("~/projects/saga"), - PaletteItem::new("journal").sublabel("~/journal"), - PaletteItem::new("dotfiles").sublabel("~/dotfiles"), - PaletteItem::new("zed.dev").sublabel("~/projects/zed.dev"), - PaletteItem::new("laminar").sublabel("~/projects/laminar"), + PaletteItem::new("zed").sublabel(SharedString::from("~/projects/zed")), + PaletteItem::new("saga").sublabel(SharedString::from("~/projects/saga")), + PaletteItem::new("journal").sublabel(SharedString::from("~/journal")), + PaletteItem::new("dotfiles").sublabel(SharedString::from("~/dotfiles")), + PaletteItem::new("zed.dev").sublabel(SharedString::from("~/projects/zed.dev")), + PaletteItem::new("laminar").sublabel(SharedString::from("~/projects/laminar")), ]) .placeholder("Recent Projects...") .empty_string("No matches") @@ -56,7 +56,11 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render( + &mut self, + _view: &mut S, + cx: &mut ViewContext, + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default"))