Skip to main content

ComposerState

Struct ComposerState 

Source
pub struct ComposerState { /* private fields */ }
Expand description

The text, the attachments, the permission mode, and the model of a Composer.

Owned by the view that shows the composer, which observes it so a change renders. It owns the prompt’s TextareaState and holds the permission and model states, and reports what the user does as a ComposerEvent. The application changes what it shows through the methods here: add an attachment, move its upload progress, clear the text.

Enter submits, and Shift+Enter starts a new line. A prompt can be submitted when it has text or a ready attachment, no attachment is still uploading, and the composer is not disabled. A submit clears the text and the attachments unless set_clear_on_submit turned that off.

Implementations§

Source§

impl ComposerState

Source

pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self

A composer with the default permission modes, an empty model catalog, and the placeholder “Hi, what do you need today?”.

Source

pub fn with_models( self, models: Entity<ModelPickerState>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

Uses models for the model picker, in place of the empty one.

Source

pub fn with_permission( self, permission: Entity<PermissionState>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

Uses permission for the permission menu, in place of the default modes.

Source

pub fn watch_status( &mut self, item: impl Into<SharedString>, state: &Entity<StatusSelectState>, cx: &mut Context<'_, Self>, )

Forwards the changes of a status item as ComposerEvent::StatusChanged under item, and renders the composer when it changes.

Source

pub fn input(&self) -> &Entity<TextareaState>

The prompt’s text state.

Source

pub fn permission(&self) -> &Entity<PermissionState>

The permission state.

Source

pub fn models(&self) -> &Entity<ModelPickerState>

The model picker state.

Source

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

The prompt’s text.

Source

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

Replaces the prompt’s text.

Source

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

Empties the prompt’s text.

Source

pub fn focus(&self, window: &mut Window, cx: &mut App)

Puts the caret in the prompt.

Source

pub fn placeholder(&self) -> &SharedString

The placeholder.

Source

pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )

Replaces the placeholder shown while the prompt is empty.

Source

pub fn max_lines(&self) -> usize

The most lines the prompt grows to before it scrolls.

Source

pub fn set_max_lines(&mut self, lines: usize, cx: &mut Context<'_, Self>)

Sets the most lines the prompt grows to, at least one.

Source

pub fn is_disabled(&self) -> bool

Whether the composer ignores input.

Source

pub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)

Disables or enables the composer: the text, the send button, and submitting.

Source

pub fn clears_on_submit(&self) -> bool

Whether a submit clears the text and the attachments.

Source

pub fn set_clear_on_submit(&mut self, clear: bool)

Whether a submit clears the text and the attachments. On by default; turn it off when the application clears them itself, once the prompt is accepted.

Source

pub fn attachments(&self) -> &[Attachment]

The attachments, in order.

Source

pub fn add_attachment( &mut self, attachment: Attachment, cx: &mut Context<'_, Self>, )

Adds an attachment at the end. An attachment with the id of one already here replaces it in place.

Source

pub fn remove_attachment( &mut self, id: &str, cx: &mut Context<'_, Self>, ) -> Option<Attachment>

Removes the attachment with id and returns it.

Source

pub fn set_attachment_progress( &mut self, id: &str, progress: Option<f32>, cx: &mut Context<'_, Self>, )

Sets the upload progress of the attachment with id: a percentage, zero for queued, or None for done.

Source

pub fn clear_attachments(&mut self, cx: &mut Context<'_, Self>)

Removes every attachment.

Source

pub fn can_submit(&self, cx: &App) -> bool

Whether the prompt can be submitted now: it has text or an attachment, nothing is still uploading, and the composer is enabled.

Source

pub fn submit( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool

Submits the prompt if it can be, and says whether it did.

Trait Implementations§

Source§

impl EventEmitter<ComposerEvent> for ComposerState

Source§

impl Focusable for ComposerState

The prompt’s focus, which holds the keyboard for the composer.

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