Skip to main content

ModelPickerState

Struct ModelPickerState 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn with_effort(self, level: u8) -> Self

Starts the effort at level, clamped to the last level.

Source

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.

Source

pub fn effort_levels(&self) -> &[SharedString]

The names of the effort levels, lowest first.

Source

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.

Source

pub fn providers(&self) -> &[ModelProvider]

The catalog, in order.

Source

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.

Source

pub fn selected(&self) -> Option<&SharedString>

The id of the chosen model.

Source

pub fn selected_model(&self) -> Option<(&ModelProvider, &ModelEntry)>

The chosen model and its provider.

Source

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.

Source

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.

Source

pub fn effort_label(&self) -> Option<SharedString>

The name of the effort level, such as “Medium”.

Source

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.

Source

pub fn favorites(&self) -> &[SharedString]

The favorite models’ ids, in the order they were starred.

Source

pub fn is_favorite(&self, id: &str) -> bool

Whether the model with id is a favorite.

Source

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.

Source

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.

Source

pub fn view(&self) -> &ModelView

What the rail has selected.

Source

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.

Source

pub fn query(&self, cx: &App) -> SharedString

The text of the search.

Source

pub fn set_query( &mut self, query: &str, window: &mut Window, cx: &mut Context<'_, Self>, )

Replaces the text of the search.

Source

pub fn visible(&self) -> Vec<(&ModelProvider, &ModelEntry)>

The models the list shows now, as (provider, model) pairs, in the order of the list.

Source

pub fn has_legacy_group(&self) -> bool

Whether the list shows the “Legacy models” header.

Source

pub fn is_legacy_open(&self) -> bool

Whether the legacy group is open.

Source

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.

Source

pub fn highlighted(&self) -> Option<SharedString>

The id of the model the keyboard or the pointer is on.

Source

pub fn is_open(&self) -> bool

Whether the panel is open.

Source

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.

Source

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§

Source§

impl EventEmitter<ModelPickerEvent> for ModelPickerState

Source§

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

Returns the focus handle associated with this view.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more