Struct ChatWidget

Source
pub struct ChatWidget<A = ()> { /* private fields */ }
Expand description

Stateful transcript with message actions and a controlled composer.

A is the application action returned by non-context callbacks. The draft is always signal-backed. Use Self::bind_session when session changes must remain observable after construction; Self::new stores its session value in private state.

§Examples

use ailloli_ui_core::{ChatSessionId, ChatSessionState};
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let session = ChatSessionState::new(ChatSessionId::new("demo"), "Demo");
let widget: ChatWidget<()> = ChatWidget::new(Some(session), State::new(String::new()));
let _ = widget;

Implementations§

Source§

impl<A: 'static> ChatWidget<A>

Source

pub fn width(self, value: impl Into<Length>) -> Self

Sets preferred width from a logical-pixel or length value.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().width(120.0);
let _ = widget;
Source

pub fn height(self, value: impl Into<Length>) -> Self

Sets preferred height from a logical-pixel or length value.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().height(40.0);
let _ = widget;
Source

pub fn min_width(self, value: impl Into<Length>) -> Self

Sets the minimum width bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_width(40.0);
let _ = widget;
Source

pub fn max_width(self, value: impl Into<Length>) -> Self

Sets the maximum width bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_width(320.0);
let _ = widget;
Source

pub fn min_height(self, value: impl Into<Length>) -> Self

Sets the minimum height bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_height(24.0);
let _ = widget;
Source

pub fn max_height(self, value: impl Into<Length>) -> Self

Sets the maximum height bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_height(240.0);
let _ = widget;
Source

pub fn fill(self) -> Self

Sets both preferred axes to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill();
let _ = widget;
Source

pub fn fill_width(self) -> Self

Sets preferred width to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_width();
let _ = widget;
Source

pub fn fill_height(self) -> Self

Sets preferred height to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_height();
let _ = widget;
Source

pub fn margin(self, value: f32) -> Self

Sets uniform outer margin in logical pixels.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().margin(8.0);
let _ = widget;
Source

pub fn padding(self, value: f32) -> Self

Sets uniform inner padding in logical pixels.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().padding(8.0);
let _ = widget;
Source

pub fn flex_grow(self) -> Self

Sets flex-grow weight to one.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow();
let _ = widget;
Source

pub fn flex_grow_by(self, value: f32) -> Self

Sets a dimensionless flex-grow weight.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow_by(2.0);
let _ = widget;
Source

pub fn flex_shrink(self, value: f32) -> Self

Sets a dimensionless flex-shrink weight.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_shrink(1.0);
let _ = widget;
Source

pub fn flex_basis(self, value: impl Into<Length>) -> Self

Sets the preferred main-axis flex basis.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_basis(80.0);
let _ = widget;
Source

pub fn align_self(self, value: AlignItems) -> Self

Overrides cross-axis alignment for this flex item.

§Examples
use ailloli_ui_core::style::AlignItems;
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().align_self(AlignItems::Center);
let _ = widget;
Source§

impl<A: 'static> ChatWidget<A>

Source

pub fn new( session: Option<ChatSessionState>, draft: impl Into<Signal<String>>, ) -> Self

Creates a widget from a session snapshot and writable draft signal.

The snapshot is moved into private state and cannot subsequently be replaced by the caller. Use Self::bind_session for a live session.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new("draft".to_string()));
let _ = widget;
Source

pub fn bind_session( session: impl Into<Signal<Option<ChatSessionState>>>, draft: impl Into<Signal<String>>, ) -> Self

Creates a widget backed by live session and draft signals.

None renders the no-session state; Some with no messages renders the empty-session state. The draft signal is updated by the text input before SetComposerDraft is emitted.

§Examples
use ailloli_ui_core::ChatSessionState;
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let session = State::new(None::<ChatSessionState>);
let draft = State::new(String::new());
let widget: ChatWidget<()> = ChatWidget::bind_session(session, draft);
let _ = widget;
Source

pub fn chat_style(self, style: ChatWidgetStyle) -> Self

Replaces the chat style and resets preferred layout width and height.

Layout builders called after this method override those two dimensions.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::{ChatWidget, ChatWidgetStyle};
let style = ChatWidgetStyle { width: 640.0, height: 320.0, ..Default::default() };
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new())).chat_style(style);
let _ = widget;
Source

pub fn compact(self, compact: bool) -> Self

Enables or disables compact rendering without changing style geometry.

Use ChatWidgetStyle::compact through Self::chat_style to also apply the compact padding, gaps, and 190-pixel preferred height.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new())).compact(true);
let _ = widget;
Source

pub fn on_action(self, f: impl Fn(ChatWidgetAction) -> A + 'static) -> Self

Dispatches the application action returned for every widget action.

For Send, Copy, and Retry this callback runs before the corresponding specialized callback when both are configured.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget = ChatWidget::new(None, State::new(String::new())).on_action(|_action| ());
let _ = widget;
Source

pub fn on_action_ctx( self, f: impl Fn(&mut EventCtx<A>, ChatWidgetAction) + 'static, ) -> Self

Handles every widget action with direct event-context access.

The handler may dispatch zero or multiple application actions and runs before specialized Send, Copy, or Retry handlers.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .on_action_ctx(|_ctx, _action| {});
let _ = widget;
Source

pub fn on_send(self, f: impl Fn(String) -> A + 'static) -> Self

Dispatches the application action returned for submitted text.

Blank-after-trimming drafts are not submitted. Non-blank text is passed unchanged, including surrounding whitespace, and the draft is not cleared.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget = ChatWidget::new(None, State::new("Hello".to_string())).on_send(|text| {
    assert_eq!(text, "Hello");
});
let _ = widget;
Source

pub fn on_send_ctx(self, f: impl Fn(&mut EventCtx<A>, String) + 'static) -> Self

Handles submitted text with direct event-context access.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .on_send_ctx(|_ctx, _text| {});
let _ = widget;
Source

pub fn on_copy(self, f: impl Fn(ChatItemId, String) -> A + 'static) -> Self

Dispatches the application action returned for a copy request.

The widget supplies the message ID and its current text but performs no clipboard write.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget = ChatWidget::new(None, State::new(String::new()))
    .on_copy(|_item_id, _text| ());
let _ = widget;
Source

pub fn on_copy_ctx( self, f: impl Fn(&mut EventCtx<A>, ChatItemId, String) + 'static, ) -> Self

Handles a copy request with direct event-context access.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .on_copy_ctx(|_ctx, _item_id, _text| {});
let _ = widget;
Source

pub fn on_retry(self, f: impl Fn(ChatItemId) -> A + 'static) -> Self

Dispatches the application action returned for a retry request.

User messages are retryable. Assistant messages are retryable only when they carry a request ID; system and tool messages are never retryable.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget = ChatWidget::new(None, State::new(String::new())).on_retry(|_item_id| ());
let _ = widget;
Source

pub fn on_retry_ctx( self, f: impl Fn(&mut EventCtx<A>, ChatItemId) + 'static, ) -> Self

Handles a retry request with direct event-context access.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .on_retry_ctx(|_ctx, _item_id| {});
let _ = widget;
Source

pub fn message_renderer( self, f: impl Fn(&ChatMessage) -> View<A> + 'static, ) -> Self

Replaces the complete built-in bubble for every message.

A custom view is responsible for body, metadata, and any Copy/Retry UI; it also bypasses the optimized retained transcript renderer.

§Examples
use ailloli_ui_runtime::component::{State, View};
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .message_renderer(|_message| View::empty());
let _ = widget;
Source

pub fn composer_accessory(self, accessory: View<A>) -> Self

Inserts a prebuilt view above the composer resize bar.

§Examples
use ailloli_ui_runtime::component::{State, View};
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .composer_accessory(View::empty());
let _ = widget;
Source

pub fn composer_controls(self, controls: ChatComposerControls) -> Self

Replaces permission/model/reasoning choices, enabled state, and height.

The values are controlled: emitted actions do not mutate this snapshot. While running, selectors are disabled and the turn button emits Stop.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::{ChatComposerControls, ChatWidget};
let controls = ChatComposerControls { running: true, ..Default::default() };
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .composer_controls(controls);
let _ = widget;
Source

pub fn follow_latest(self, enabled: bool) -> Self

Sets whether the vertical transcript scroll follows its end.

§Examples
use ailloli_ui_runtime::component::State;
use ailloli_ui_widgets::controls::ChatWidget;
let widget: ChatWidget<()> = ChatWidget::new(None, State::new(String::new()))
    .follow_latest(false);
let _ = widget;

Trait Implementations§

Source§

impl<A: 'static> IntoView<A> for ChatWidget<A>

Source§

fn into_view(self) -> View<A>

Consumes a builder/value and returns its declarative view tree. Read more
Source§

impl<A: 'static> LayoutExt for ChatWidget<A>

Source§

fn layout_mut(&mut self) -> &mut LayoutStyle

Returns the widget’s mutable declarative size/inset state. Read more

Auto Trait Implementations§

§

impl<A> Freeze for ChatWidget<A>

§

impl<A = ()> !RefUnwindSafe for ChatWidget<A>

§

impl<A = ()> !Send for ChatWidget<A>

§

impl<A = ()> !Sync for ChatWidget<A>

§

impl<A> Unpin for ChatWidget<A>

§

impl<A = ()> !UnwindSafe for ChatWidget<A>

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<T, A> FlexItemExt<A> for T
where T: IntoView<A>,

Source§

fn flex_grow(self) -> View<A>

Sets flex-grow weight to one. Read more
Source§

fn flex_grow_by(self, value: f32) -> View<A>

Sets the dimensionless flex-grow weight. Read more
Source§

fn flex_shrink(self, value: f32) -> View<A>

Sets the dimensionless flex-shrink weight. Read more
Source§

fn flex_basis(self, value: impl Into<Length>) -> View<A>

Sets the preferred main-axis flex basis. Read more
Source§

fn align_self(self, value: AlignItems) -> View<A>

Overrides the parent cross-axis alignment for this view. Read more
Source§

fn fill_width(self) -> View<A>

Marks width as parent-fill in the view size hint. Read more
Source§

fn fill_height(self) -> View<A>

Marks height as parent-fill in the view size hint. Read more
Source§

fn fill(self) -> View<A>

Marks both axes as parent-fill in the view size hint. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T, A> IntoViewKeyExt<A> for T
where T: IntoView<A>,

§

fn key(self, key: impl Into<String>) -> View<A>

Converts self, assigns the owned key, and returns the view. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,