pub struct Composer { /* private fields */ }Expand description
A reusable chat input.
The composer owns its TextareaState and emits ComposerEvent instead
of calling the host directly. A host creates one entity, subscribes to it,
and calls set_streaming when the worker starts and
stops.
Implementations§
Source§impl Composer
impl Composer
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
Create a composer with a one-to-six-line auto-growing input.
Sourcepub fn send_icon(self, icon: impl Into<ChatIcon>) -> Self
pub fn send_icon(self, icon: impl Into<ChatIcon>) -> Self
Replace the send button’s mark.
A raster ChatIcon has no monochrome form, so the send button falls
back to the catalog Send icon.
Sourcepub fn set_send_icon(
&mut self,
icon: impl Into<ChatIcon>,
cx: &mut Context<'_, Self>,
)
pub fn set_send_icon( &mut self, icon: impl Into<ChatIcon>, cx: &mut Context<'_, Self>, )
Replace the send button’s mark and redraw.
Sourcepub fn textarea(&self) -> &Entity<TextareaState>
pub fn textarea(&self) -> &Entity<TextareaState>
The underlying textarea, for hosts that need selection or IME access.
Sourcepub fn value(&self, cx: &App) -> SharedString
pub fn value(&self, cx: &App) -> SharedString
Current text, including untrimmed whitespace.
Sourcepub fn set_draft(
&mut self,
text: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_draft( &mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )
Replace the draft and move the caret to the end.
Sourcepub fn set_streaming(&mut self, streaming: bool, cx: &mut Context<'_, Self>)
pub fn set_streaming(&mut self, streaming: bool, cx: &mut Context<'_, Self>)
Switch between send and stop.
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Returns whether the composer currently offers Stop.
Sourcepub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
pub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
Disable submission and editing.
Sourcepub fn set_hint(
&mut self,
hint: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn set_hint( &mut self, hint: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Override the line under the input.
Sourcepub fn submit(&mut self, cx: &mut Context<'_, Self>)
pub fn submit(&mut self, cx: &mut Context<'_, Self>)
Emit ComposerEvent::Submit for non-empty text.
Called by Ctrl/⌘+Enter and by the Send button.
Sourcepub fn request_stop(&mut self, cx: &mut Context<'_, Self>)
pub fn request_stop(&mut self, cx: &mut Context<'_, Self>)
Emit ComposerEvent::Stop while a generation is running.
Sourcepub fn submit_or_stop(&mut self, cx: &mut Context<'_, Self>)
pub fn submit_or_stop(&mut self, cx: &mut Context<'_, Self>)
Submit the current draft, or emit ComposerEvent::Stop while streaming.
Trait Implementations§
impl EventEmitter<ComposerEvent> for Composer
Source§impl Focusable for Composer
impl Focusable for Composer
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for Composer
impl !Send for Composer
impl !Sync for Composer
impl !UnwindSafe for Composer
impl Freeze for Composer
impl Unpin for Composer
impl UnsafeUnpin for Composer
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