pub struct ModelPickerState { /* private fields */ }Expand description
The catalog, the chosen model and its effort, the favorites, the view
the rail shows, the search, and the open panel of a ModelPicker.
Owned by the view that shows the picker, which observes it so a change
renders. The choice and the favorites are kept by model id, so a catalog
that changes under them keeps the ones whose model is still there. The
state does not save anything: the application listens for
ModelPickerEvent::FavoriteChanged and seeds the favorites again with
with_favorites.
Implementations§
Source§impl ModelPickerState
impl ModelPickerState
Sourcepub fn new(
providers: impl IntoIterator<Item = ModelProvider>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Self
pub fn new( providers: impl IntoIterator<Item = ModelProvider>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self
A picker over providers with nothing chosen and no favorites. The
rail starts on the first provider.
Sourcepub fn with_selected(self, id: impl Into<SharedString>) -> Self
pub fn with_selected(self, id: impl Into<SharedString>) -> Self
Chooses the model with id, if the catalog has it. The rail moves
to its provider.
Sourcepub fn with_view(self, view: ModelView) -> Self
pub fn with_view(self, view: ModelView) -> Self
Starts on view: the favorites, or a provider the catalog holds.
A provider it does not hold changes nothing.
Sourcepub fn with_effort(self, level: u8) -> Self
pub fn with_effort(self, level: u8) -> Self
Starts the effort at level, clamped to the last level.
Sourcepub fn with_effort_levels(
self,
levels: impl IntoIterator<Item = impl Into<SharedString>>,
) -> Self
pub fn with_effort_levels( self, levels: impl IntoIterator<Item = impl Into<SharedString>>, ) -> Self
The names of the effort levels, lowest first, in place of
EFFORT_LABELS. EffortChanged and
effort are indices into them. An empty list
changes nothing. The effort is clamped to the new last level.
Sourcepub fn effort_levels(&self) -> &[SharedString]
pub fn effort_levels(&self) -> &[SharedString]
The names of the effort levels, lowest first.
Sourcepub fn with_favorites(
self,
ids: impl IntoIterator<Item = impl Into<SharedString>>,
) -> Self
pub fn with_favorites( self, ids: impl IntoIterator<Item = impl Into<SharedString>>, ) -> Self
Starts with these favorites, in this order. An id the catalog does not hold is ignored, and so is a repeat.
Sourcepub fn providers(&self) -> &[ModelProvider]
pub fn providers(&self) -> &[ModelProvider]
The catalog, in order.
Sourcepub fn set_providers(
&mut self,
providers: impl IntoIterator<Item = ModelProvider>,
cx: &mut Context<'_, Self>,
)
pub fn set_providers( &mut self, providers: impl IntoIterator<Item = ModelProvider>, cx: &mut Context<'_, Self>, )
Replaces the catalog. The choice and the favorites stay for models still in the catalog and are dropped for the others.
Sourcepub fn selected(&self) -> Option<&SharedString>
pub fn selected(&self) -> Option<&SharedString>
The id of the chosen model.
Sourcepub fn selected_model(&self) -> Option<(&ModelProvider, &ModelEntry)>
pub fn selected_model(&self) -> Option<(&ModelProvider, &ModelEntry)>
The chosen model and its provider.
Sourcepub fn select(
&mut self,
id: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn select( &mut self, id: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Chooses the model with id and emits Selected. An unknown id, or
the model already chosen, changes nothing. The rail moves to the
model’s provider.
Sourcepub fn effort(&self) -> Option<u8>
pub fn effort(&self) -> Option<u8>
The effort level of the chosen model, an index into
effort_levels (0 to 5 by default), or None
when no model is chosen or the chosen model has no effort setting.
Sourcepub fn effort_label(&self) -> Option<SharedString>
pub fn effort_label(&self) -> Option<SharedString>
The name of the effort level, such as “Medium”.
Sourcepub fn set_effort(&mut self, level: u8, cx: &mut Context<'_, Self>)
pub fn set_effort(&mut self, level: u8, cx: &mut Context<'_, Self>)
Sets the effort to level, clamped to the last level, and emits
EffortChanged.
Sourcepub fn favorites(&self) -> &[SharedString]
pub fn favorites(&self) -> &[SharedString]
The favorite models’ ids, in the order they were starred.
Sourcepub fn is_favorite(&self, id: &str) -> bool
pub fn is_favorite(&self, id: &str) -> bool
Whether the model with id is a favorite.
Sourcepub fn set_favorite(
&mut self,
id: impl Into<SharedString>,
favorite: bool,
cx: &mut Context<'_, Self>,
)
pub fn set_favorite( &mut self, id: impl Into<SharedString>, favorite: bool, cx: &mut Context<'_, Self>, )
Stars or unstars the model with id and emits FavoriteChanged.
An unknown id, or a model already in that state, changes nothing.
Sourcepub fn toggle_favorite(
&mut self,
id: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn toggle_favorite( &mut self, id: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Stars the model if it is not a favorite and unstars it if it is.
Sourcepub fn set_view(
&mut self,
view: ModelView,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_view( &mut self, view: ModelView, window: &mut Window, cx: &mut Context<'_, Self>, )
Shows view and clears the search so its models show. A provider
the catalog does not hold changes nothing.
Sourcepub fn query(&self, cx: &App) -> SharedString
pub fn query(&self, cx: &App) -> SharedString
The text of the search.
Sourcepub fn set_query(
&mut self,
query: &str,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_query( &mut self, query: &str, window: &mut Window, cx: &mut Context<'_, Self>, )
Replaces the text of the search.
Sourcepub fn visible(&self) -> Vec<(&ModelProvider, &ModelEntry)>
pub fn visible(&self) -> Vec<(&ModelProvider, &ModelEntry)>
The models the list shows now, as (provider, model) pairs, in
the order of the list.
Sourcepub fn has_legacy_group(&self) -> bool
pub fn has_legacy_group(&self) -> bool
Whether the list shows the “Legacy models” header.
Sourcepub fn is_legacy_open(&self) -> bool
pub fn is_legacy_open(&self) -> bool
Whether the legacy group is open.
Sourcepub fn set_legacy_open(&mut self, open: bool, cx: &mut Context<'_, Self>)
pub fn set_legacy_open(&mut self, open: bool, cx: &mut Context<'_, Self>)
Opens or closes the legacy group. It is closed until it is opened, and closes again when the view changes.
Sourcepub fn highlighted(&self) -> Option<SharedString>
pub fn highlighted(&self) -> Option<SharedString>
The id of the model the keyboard or the pointer is on.
Sourcepub fn set_open(
&mut self,
open: bool,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_open( &mut self, open: bool, window: &mut Window, cx: &mut Context<'_, Self>, )
Opens or closes the panel and emits OpenChanged. Closing clears
the search.
Sourcepub fn select_number(
&mut self,
number: usize,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn select_number( &mut self, number: usize, window: &mut Window, cx: &mut Context<'_, Self>, )
Chooses the model on the numberth row of the list, counting from
1 and only models, as Cmd+1 to Cmd+9 do, and closes the panel.
Trait Implementations§
impl EventEmitter<ModelPickerEvent> for ModelPickerState
Source§impl Focusable for ModelPickerState
The search field’s focus, which holds the keyboard while the panel is
open.
impl Focusable for ModelPickerState
The search field’s focus, which holds the keyboard while the panel is open.
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for ModelPickerState
impl !Send for ModelPickerState
impl !Sync for ModelPickerState
impl !UnwindSafe for ModelPickerState
impl Freeze for ModelPickerState
impl Unpin for ModelPickerState
impl UnsafeUnpin for ModelPickerState
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> 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> 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