pub struct SelectItem<V> { /* private fields */ }Expand description
One choice in a Select menu.
The value is the item’s identity: it keys the row’s element id, the selection, and the events. The label is what the row and the trigger show. An item can carry a description under its label, an icon or any element before it, extra words the search matches, and a disabled state.
use gpui_cn::{SelectItem, gpui_kit::assets::IconName};
let _ = SelectItem::new("finder", "Finder").icon(IconName::Folder);
let _ = SelectItem::new("never", "Never ask for approval")
.description("Blocked actions fail instead of requesting approval");
let _ = SelectItem::new("de", "Deutsch").keywords(["german"]);
let _ = SelectItem::new(42, "Item 42");Implementations§
Source§impl<V: SelectValue> SelectItem<V>
impl<V: SelectValue> SelectItem<V>
Sourcepub fn new(value: V, label: impl Into<SharedString>) -> Self
pub fn new(value: V, label: impl Into<SharedString>) -> Self
An item with a stable value and the label it shows.
Sourcepub fn description(self, description: impl Into<SharedString>) -> Self
pub fn description(self, description: impl Into<SharedString>) -> Self
A second line under the label, in the muted color.
Sourcepub fn icon(self, icon: impl Into<Icon>) -> Self
pub fn icon(self, icon: impl Into<Icon>) -> Self
An icon before the label, at the icon size, in the row’s text color. The trigger shows the selected item’s icon too.
Sourcepub fn leading<E: IntoElement>(
self,
build: impl Fn(&mut Window, &mut App) -> E + Send + Sync + 'static,
) -> Self
pub fn leading<E: IntoElement>( self, build: impl Fn(&mut Window, &mut App) -> E + Send + Sync + 'static, ) -> Self
Any element before the label, built each frame: a color swatch, an
avatar, an application icon. It replaces the icon in the row; the
trigger shows it too. The builder is Send + Sync so rows can come
from a search on another thread.
Sourcepub fn keywords(
self,
keywords: impl IntoIterator<Item = impl Into<SharedString>>,
) -> Self
pub fn keywords( self, keywords: impl IntoIterator<Item = impl Into<SharedString>>, ) -> Self
Words the search matches besides the label, such as a language’s English name beside its own.
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Whether the item can be chosen. A disabled item shows in the muted color and the keyboard skips it.
Sourcepub fn key(&self) -> SharedString
pub fn key(&self) -> SharedString
The stable name of the item’s row: its value’s key.
Sourcepub fn label(&self) -> &SharedString
pub fn label(&self) -> &SharedString
The text the row and the trigger show.
Sourcepub fn description_text(&self) -> Option<&SharedString>
pub fn description_text(&self) -> Option<&SharedString>
The line under the label, if any.
Sourcepub fn icon_source(&self) -> Option<&Icon>
pub fn icon_source(&self) -> Option<&Icon>
The icon before the label, if the leading element is one.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Whether the item can be chosen.
Sourcepub fn matches(&self, query: &str) -> bool
pub fn matches(&self, query: &str) -> bool
Whether the query matches the label or a keyword, as a fuzzy subsequence ignoring case. An empty query matches everything.
Sourcepub fn match_score(&self, query: &str) -> Option<u32>
pub fn match_score(&self, query: &str) -> Option<u32>
How well the query matches: the label’s score, or half the best
keyword’s score, since a keyword is a weaker hit. None for no
match, and 0 for an empty query.
Trait Implementations§
Source§impl<V: Clone> Clone for SelectItem<V>
impl<V: Clone> Clone for SelectItem<V>
Source§impl<V: SelectValue> Debug for SelectItem<V>
impl<V: SelectValue> Debug for SelectItem<V>
Source§impl<V: SelectValue> From<SelectItem<V>> for SelectEntry<V>
impl<V: SelectValue> From<SelectItem<V>> for SelectEntry<V>
Source§fn from(item: SelectItem<V>) -> Self
fn from(item: SelectItem<V>) -> Self
Auto Trait Implementations§
impl<V> !RefUnwindSafe for SelectItem<V>
impl<V> !UnwindSafe for SelectItem<V>
impl<V> Freeze for SelectItem<V>where
V: Freeze,
impl<V> Send for SelectItem<V>where
V: Send,
impl<V> Sync for SelectItem<V>where
V: Sync,
impl<V> Unpin for SelectItem<V>where
V: Unpin,
impl<V> UnsafeUnpin for SelectItem<V>where
V: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more