pub struct Chat { /* private fields */ }Expand description
A conversation over a field to write in. It fills what its parent gives it and follows the newest message.
It does not know who answers: on_send gets what the person wrote, already in
the list, and whoever answers adds to messages, now or later.
use ravenrs_reactive::State;
use ravenrs_widgets::{Chat, ChatMessage};
let messages = State::new(Vec::<ChatMessage>::new());
let answers = messages.clone();
let chat = Chat::new(messages.binding())
.placeholder("Ask something")
.examples(["How do I start?"])
.on_send(move |_text| answers.update(|m| m.push(ChatMessage::assistant("Hello!"))));Implementations§
Source§impl Chat
impl Chat
Sourcepub fn new(messages: Binding<Vec<ChatMessage>>) -> Self
pub fn new(messages: Binding<Vec<ChatMessage>>) -> Self
A conversation over messages.
Sourcepub fn placeholder(self, text: impl Into<String>) -> Self
pub fn placeholder(self, text: impl Into<String>) -> Self
Muted text inside the empty field.
Sourcepub fn examples(
self,
examples: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn examples( self, examples: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Things to ask, offered as buttons before the first message.
Sourcepub fn busy(self, busy: bool) -> Self
pub fn busy(self, busy: bool) -> Self
Whether an answer is on its way: nothing is sent until it arrives, and what is being written stays in the field.
Sourcepub fn on_listen(self, handler: impl Fn(String) + 'static) -> Self
pub fn on_listen(self, handler: impl Fn(String) + 'static) -> Self
Puts a button to hear each answer, which handler gets as text.
Sourcepub fn on_link(self, handler: impl Fn(String) + 'static) -> Self
pub fn on_link(self, handler: impl Fn(String) + 'static) -> Self
Called with the address of a link in a ChatMessage::formatted message.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Chat
impl !Send for Chat
impl !Sync for Chat
impl !UnwindSafe for Chat
impl Freeze for Chat
impl Unpin for Chat
impl UnsafeUnpin for Chat
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
Mutably borrows from an owned value. Read more
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Adds padding inside the box, in logical pixels.
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Paints a background behind the content.
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
Fixes the width and/or height in logical pixels;
None keeps the content size.