Skip to main content

Element

Struct Element 

Source
pub struct Element {
    pub type_id: TypeId,
    pub widget: Box<dyn Widget>,
}
Expand description

A container for any widget implementing the Widget trait. A container for any widget implementing the Widget trait.

This is the primary type used to store and manipulate widgets in layout trees. Element wraps a widget in a dynamic trait object.

Use Element::new to convert a widget into an Element.

Fields§

§type_id: TypeId§widget: Box<dyn Widget>

Implementations§

Source§

impl Element

Source

pub fn new<W>(widget: W) -> Self
where W: Widget + 'static,

Creates a new Element from a given widget.

This is commonly used to wrap widgets when composing layouts.

§Example
let span = Span::new("Hello");
let element = Element::new(span);
Source

pub fn map<W: Widget + 'static, F: FnOnce(W) -> W>(self, f: F) -> Self

Source

pub fn downcast_ref<W: Widget>(&self) -> Option<&W>

Downcasts widget stored in the Element to given type, returns optional reference to the downcast widget on success.

Source

pub fn downcast_mut<W: Widget>(&mut self) -> Option<&mut W>

Downcasts widget stored in the Element to given type, returns optional mutable reference to the downcast widget on success.

Trait Implementations§

Source§

impl Debug for Element

Source§

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

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

impl<W> From<BgGrad<W>> for Element
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 Element
where W: Widget + 'static,

Source§

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

Converts to this type from the input type.
Source§

impl From<Grad> for Element

Source§

fn from(value: Grad) -> Self

Converts to this type from the input type.
Source§

impl From<Grid> for Element

Source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
Source§

impl From<Layout> for Element

Source§

fn from(value: Layout) -> Self

Converts to this type from the input type.
Source§

impl From<List> for Element

Source§

fn from(value: List) -> Self

Converts to this type from the input type.
Source§

impl From<Overlay> for Element

Source§

fn from(value: Overlay) -> Self

Converts to this type from the input type.
Source§

impl From<Paragraph> for Element

Source§

fn from(value: Paragraph) -> Self

Converts to this type from the input type.
Source§

impl From<ProgressBar> for Element

Source§

fn from(value: ProgressBar) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<Scrollbar> for Element

Source§

fn from(value: Scrollbar) -> Self

Converts to this type from the input type.
Source§

impl From<Spacer> for Element

Source§

fn from(value: Spacer) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Element

Source§

fn from(value: Span) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Element
where T: AsRef<str>,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl From<Table> for Element

Source§

fn from(value: Table) -> Self

Converts to this type from the input type.
Source§

impl Widget for Element

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

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

Gets widget’s children

Auto Trait Implementations§

§

impl Freeze for Element

§

impl !RefUnwindSafe for Element

§

impl !Send for Element

§

impl !Sync for Element

§

impl Unpin for Element

§

impl !UnwindSafe for Element

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

Source§

fn scale(self) -> T

Scale this type to the given other type.
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.