Skip to main content

TypingWidget

Struct TypingWidget 

Source
pub struct TypingWidget<C> {
    pub size_and_position: SizeAndPosition,
    pub render_function: Option<Box<dyn Fn((u16, u16), (u16, u16), &[&str; 2], bool) -> Option<Vec<Span>>>>,
    pub typed_text: String,
    pub selected: bool,
    pub cursor_pos: usize,
    /* private fields */
}
Expand description

A widget that renders static content using a provided closure (i.e. a title box or description). Suitable for content that doesn’t change frequently or in response to events. TypingWidgetBuilder is the associated builder for creating instances of this widget. The generic parameter C represents the application data type, which can be any type defined by the user.

Fields§

§size_and_position: SizeAndPosition

Configuration for the widget’s size and position, supporting both static and dynamic layouts.

§render_function: Option<Box<dyn Fn((u16, u16), (u16, u16), &[&str; 2], bool) -> Option<Vec<Span>>>>

Optional closure that generates the widget’s rendered content based on size and position.

§typed_text: String

The text that has been typed into the widget so far.

§selected: bool

Indicates whether the widget is currently selected (focused for input).

§cursor_pos: usize

Implementations§

Source§

impl<C> TypingWidget<C>

Source

pub fn new( name: String, size_and_position: SizeAndPosition, render_function: Option<Box<dyn Fn((u16, u16), (u16, u16), &[&str; 2], bool) -> Option<Vec<Span>>>>, depth: u16, display_area: &Rect, ) -> Result<(TypingWidget<C>, Window), WidgetErr>

Creates a new TypingWidget and its associated window.

§Arguments
  • name - Unique identifier for the widget
  • size_and_position - Configuration for size and positioning
  • render_function - Optional closure that renders content given size and position
  • depth - Z-index for rendering order
  • display_area - Current terminal area for initial size/position calculation
§Returns

Result containing the widget and window, or error if dimensions are invalid

When possible, an implementation of WidgetBuilder should be used instead, both for safety, simplicity, and consistency.

Trait Implementations§

Source§

impl<C> Widget<C> for TypingWidget<C>

Implementation of the methods for TypingWidget

Source§

fn get_window_ref(&self) -> String

Returns the widget’s name as an identifier. The rendering backend relies on String names instead of widgets.

Source§

fn update_with_events( &mut self, data: &mut C, app: &mut App<C>, scene: &mut Scene<C>, )

Handles event updates. However, compared to the other widgets, this one doesn’t directly act to modify the widget, but rather to respond to changes in text input.

Source§

fn update_render(&mut self, window: &mut Window, area: &Rect) -> bool

Updates the widget’s rendering based on current size and position. Called automatically during render passes. If Some(render_closure) is provided, that closure will be called. If the closure returns Some(Vec<Span>), then the rendered content will be set as such.

Source§

fn get_children_indexes(&self) -> Vec<usize>

Returns the indices of child widgets in the scene graph.

Source§

fn add_child_index(&mut self, index: usize)

Adds a child widget index to this widget.

Source§

fn remove_child_index(&mut self, index: usize)

Removes a child widget index from this widget

Source§

fn clear_children_indexes(&mut self)

Clears all child widget indices from this widget

Source§

fn get_parent_index(&self) -> Option<usize>

Returns the parent widget index if one exists, otherwise None.

Source§

fn set_parent_index(&mut self, index: Option<usize>)

Sets the parent widget index for this widget, or None for a root node.

Source§

fn is_collided(&self, position: (u16, u16)) -> bool

Determines if a given position collides with the widget’s area.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for TypingWidget<C>

§

impl<C> !Send for TypingWidget<C>

§

impl<C> !Sync for TypingWidget<C>

§

impl<C> !UnwindSafe for TypingWidget<C>

§

impl<C> Freeze for TypingWidget<C>
where Option<Box<dyn Fn(&mut dyn Widget<C>, &mut C, &mut App<C>, &mut Scene<C>)>>: Freeze, PhantomData<C>: Freeze,

§

impl<C> Unpin for TypingWidget<C>
where Option<Box<dyn Fn(&mut dyn Widget<C>, &mut C, &mut App<C>, &mut Scene<C>)>>: Unpin, PhantomData<C>: Unpin,

§

impl<C> UnsafeUnpin for TypingWidget<C>
where Option<Box<dyn Fn(&mut dyn Widget<C>, &mut C, &mut App<C>, &mut Scene<C>)>>: UnsafeUnpin, PhantomData<C>: UnsafeUnpin,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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