Use ListItem
s in Picker
story
This commit is contained in:
parent
1ee109cec7
commit
ecb3bd7f59
1 changed files with 5 additions and 13 deletions
|
@ -5,6 +5,7 @@ use gpui::{
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme2::ActiveTheme;
|
use theme2::ActiveTheme;
|
||||||
|
use ui::{Label, ListItem};
|
||||||
|
|
||||||
pub struct PickerStory {
|
pub struct PickerStory {
|
||||||
picker: View<Picker<Delegate>>,
|
picker: View<Picker<Delegate>>,
|
||||||
|
@ -36,7 +37,7 @@ impl Delegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PickerDelegate for Delegate {
|
impl PickerDelegate for Delegate {
|
||||||
type ListItem = Div;
|
type ListItem = ListItem;
|
||||||
|
|
||||||
fn match_count(&self) -> usize {
|
fn match_count(&self) -> usize {
|
||||||
self.candidates.len()
|
self.candidates.len()
|
||||||
|
@ -52,7 +53,6 @@ impl PickerDelegate for Delegate {
|
||||||
selected: bool,
|
selected: bool,
|
||||||
cx: &mut gpui::ViewContext<Picker<Self>>,
|
cx: &mut gpui::ViewContext<Picker<Self>>,
|
||||||
) -> Option<Self::ListItem> {
|
) -> Option<Self::ListItem> {
|
||||||
let colors = cx.theme().colors();
|
|
||||||
let Some(candidate_ix) = self.matches.get(ix) else {
|
let Some(candidate_ix) = self.matches.get(ix) else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
@ -60,17 +60,9 @@ impl PickerDelegate for Delegate {
|
||||||
let candidate = SharedString::from(self.candidates[*candidate_ix].string.clone());
|
let candidate = SharedString::from(self.candidates[*candidate_ix].string.clone());
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
div()
|
ListItem::new(ix)
|
||||||
.text_color(colors.text)
|
.selected(selected)
|
||||||
.when(selected, |s| {
|
.child(Label::new(candidate)),
|
||||||
s.border_l_10().border_color(colors.terminal_ansi_yellow)
|
|
||||||
})
|
|
||||||
.hover(|style| {
|
|
||||||
style
|
|
||||||
.bg(colors.element_active)
|
|
||||||
.text_color(colors.text_accent)
|
|
||||||
})
|
|
||||||
.child(candidate),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue