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
impl ComposerState
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
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?”.
Sourcepub fn with_models(
self,
models: Entity<ModelPickerState>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Self
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.
Sourcepub fn with_permission(
self,
permission: Entity<PermissionState>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Self
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.
Sourcepub fn watch_status(
&mut self,
item: impl Into<SharedString>,
state: &Entity<StatusSelectState>,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn input(&self) -> &Entity<TextareaState>
pub fn input(&self) -> &Entity<TextareaState>
The prompt’s text state.
Sourcepub fn permission(&self) -> &Entity<PermissionState>
pub fn permission(&self) -> &Entity<PermissionState>
The permission state.
Sourcepub fn models(&self) -> &Entity<ModelPickerState>
pub fn models(&self) -> &Entity<ModelPickerState>
The model picker state.
Sourcepub fn text(&self, cx: &App) -> SharedString
pub fn text(&self, cx: &App) -> SharedString
The prompt’s text.
Sourcepub fn set_text(
&mut self,
text: &str,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_text( &mut self, text: &str, window: &mut Window, cx: &mut Context<'_, Self>, )
Replaces the prompt’s text.
Sourcepub fn clear_text(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn clear_text(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
Empties the prompt’s text.
Sourcepub fn placeholder(&self) -> &SharedString
pub fn placeholder(&self) -> &SharedString
The placeholder.
Sourcepub fn set_placeholder(
&mut self,
placeholder: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn set_max_lines(&mut self, lines: usize, cx: &mut Context<'_, Self>)
pub fn set_max_lines(&mut self, lines: usize, cx: &mut Context<'_, Self>)
Sets the most lines the prompt grows to, at least one.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Whether the composer ignores input.
Sourcepub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
pub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
Disables or enables the composer: the text, the send button, and submitting.
Sourcepub fn clears_on_submit(&self) -> bool
pub fn clears_on_submit(&self) -> bool
Whether a submit clears the text and the attachments.
Sourcepub fn set_clear_on_submit(&mut self, clear: bool)
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.
Sourcepub fn attachments(&self) -> &[Attachment]
pub fn attachments(&self) -> &[Attachment]
The attachments, in order.
Sourcepub fn add_attachment(
&mut self,
attachment: Attachment,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn remove_attachment(
&mut self,
id: &str,
cx: &mut Context<'_, Self>,
) -> Option<Attachment>
pub fn remove_attachment( &mut self, id: &str, cx: &mut Context<'_, Self>, ) -> Option<Attachment>
Removes the attachment with id and returns it.
Sourcepub fn set_attachment_progress(
&mut self,
id: &str,
progress: Option<f32>,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn clear_attachments(&mut self, cx: &mut Context<'_, Self>)
pub fn clear_attachments(&mut self, cx: &mut Context<'_, Self>)
Removes every attachment.
Sourcepub fn can_submit(&self, cx: &App) -> bool
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.
Trait Implementations§
impl EventEmitter<ComposerEvent> for ComposerState
Source§impl Focusable for ComposerState
The prompt’s focus, which holds the keyboard for the composer.
impl Focusable for ComposerState
The prompt’s focus, which holds the keyboard for the composer.
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for ComposerState
impl !Send for ComposerState
impl !Sync for ComposerState
impl !UnwindSafe for ComposerState
impl Freeze for ComposerState
impl Unpin for ComposerState
impl UnsafeUnpin for ComposerState
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