Skip to main content

Widget

Trait Widget 

Source
pub trait Widget: Any {
    // Required methods
    fn render(&self, buffer: &mut Buffer, rect: Rect, cache: &mut Cache);
    fn height(&self, size: &Vec2) -> usize;
    fn width(&self, size: &Vec2) -> usize;

    // Provided method
    fn children(&self) -> Vec<&Element> { ... }
}
Expand description

Trait implemented by all the widgets. Trait implemented by all the widgets.

A widget is a visual component that can render itself to a Buffer and report its size requirements for layout purposes.

Use Element to store and manipulate widgets in a uniform way.

Users will use Widget trait directly only when implementing custom widget, otherwise they will use built-in widgets like [Span], [List] and so on.

Required Methods§

Source

fn render(&self, buffer: &mut Buffer, rect: Rect, cache: &mut Cache)

Renders the widget into the given Buffer within the provided Rect bounds.

Source

fn height(&self, size: &Vec2) -> usize

Returns the height of the Widget based on the width of the given size.

Source

fn width(&self, size: &Vec2) -> usize

Returns the width of the Widget based on the height of the given size.

Provided Methods§

Source

fn children(&self) -> Vec<&Element>

Gets widget’s children

Implementations§

Source§

impl dyn Widget

Source

pub fn as_any(&self) -> &dyn Any

Source

pub fn as_any_mut(&mut self) -> &mut dyn Any

Trait Implementations§

Source§

impl Debug for dyn Widget

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<W> From<BgGrad<W>> for Box<dyn Widget>
where W: Widget + 'static,

Source§

fn from(value: BgGrad<W>) -> Self

Converts to this type from the input type.
Source§

impl<W> From<Block<W>> for Box<dyn Widget>
where W: Widget + 'static,

Source§

fn from(value: Block<W>) -> Self

Converts to this type from the input type.
Source§

impl From<Grad> for Box<dyn Widget>

Source§

fn from(value: Grad) -> Self

Converts to this type from the input type.
Source§

impl From<Grid> for Box<dyn Widget>

Source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
Source§

impl From<Layout> for Box<dyn Widget>

Source§

fn from(value: Layout) -> Self

Converts to this type from the input type.
Source§

impl From<List> for Box<dyn Widget>

Source§

fn from(value: List) -> Self

Converts to this type from the input type.
Source§

impl From<Overlay> for Box<dyn Widget>

Source§

fn from(value: Overlay) -> Self

Converts to this type from the input type.
Source§

impl From<Paragraph> for Box<dyn Widget>

Source§

fn from(value: Paragraph) -> Self

Converts to this type from the input type.
Source§

impl From<ProgressBar> for Box<dyn Widget>

Source§

fn from(value: ProgressBar) -> Self

Converts to this type from the input type.
Source§

impl<W> From<Scrollable<W>> for Box<dyn Widget>
where W: Widget + 'static,

Source§

fn from(value: Scrollable<W>) -> Self

Converts to this type from the input type.
Source§

impl From<Scrollbar> for Box<dyn Widget>

Source§

fn from(value: Scrollbar) -> Self

Converts to this type from the input type.
Source§

impl From<Spacer> for Box<dyn Widget>

Source§

fn from(value: Spacer) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Box<dyn Widget>

Source§

fn from(value: Span) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Box<dyn Widget>
where T: AsRef<str>,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl From<Table> for Box<dyn Widget>

Source§

fn from(value: Table) -> Self

Converts to this type from the input type.

Implementors§