El

Struct El 

Source
pub struct El(/* private fields */);
Expand description

An html element with associated data sharing the same lifetime.

There are a number of ref_ and non-ref_ method pairs. The non-ref_ methods are chainable but consume and return the element, for use during element creation. The ref_ take a reference and as such don’t consume or return the element.

El values are clonable. Note that if you store a parent element in a child element you’ll end up with a reference cycle and the subtree will never be freed. You can use weak() to get a weak reference if you want to do this.

Implementations§

Source§

impl El

Source

pub fn text(self, text: &str) -> Self

Set text contents.

Source

pub fn ref_text(&self, text: &str) -> &Self

Source

pub fn id(self, id: &str) -> Self

Set the element id.

Source

pub fn attr(self, key: &str, value: &str) -> Self

Set an arbitrary attribute. Note there are special methods for setting class and id which may afford safer workflows.

Source

pub fn ref_attr(&self, key: &str, value: &str) -> &Self

Source

pub fn ref_remove_attr(&self, key: &str) -> &Self

Remove an attribute from the element.

Source

pub fn classes(self, keys: &[&str]) -> Self

Add (if not existing) all of the listed keys.

Source

pub fn ref_classes(&self, keys: &[&str]) -> &Self

Source

pub fn ref_remove_classes(&self, keys: &[&str]) -> &Self

Remove (if not existing) all of the listed keys.

Source

pub fn ref_modify_classes(&self, keys: &[(&str, bool)]) -> &Self

Source

pub fn push(self, add: El) -> Self

Add a single element to the end.

Source

pub fn ref_push(&self, add: El) -> &Self

Source

pub fn extend(self, add: Vec<El>) -> Self

Add multiple elements to the end.

Source

pub fn ref_extend(&self, add: Vec<El>) -> &Self

Source

pub fn ref_splice(&self, offset: usize, remove: usize, add: Vec<El>) -> &Self

Add and remove multiple elements.

Source

pub fn ref_clear(&self) -> &Self

Remove all children.

Source

pub fn own<T: 'static>(self, supplier: impl FnOnce(&El) -> T) -> Self

Attach the value to this scope, so it doesn’t get dropped until the element is removed from the tree.

Source

pub fn ref_own<T: 'static>(&self, supplier: impl FnOnce(&El) -> T) -> &Self

Source

pub fn on(self, event: &'static str, cb: impl FnMut(&Event) + 'static) -> Self

Source

pub fn on_with_options( self, event: &'static str, opts: EventListenerOptions, cb: impl FnMut(&Event) + 'static, ) -> Self

Source

pub fn ref_on( &self, event: &'static str, cb: impl FnMut(&Event) + 'static, ) -> &Self

Source

pub fn ref_on_with_options( &self, event: &'static str, opts: EventListenerOptions, cb: impl FnMut(&Event) + 'static, ) -> &Self

Source

pub fn on_resize(self, cb: impl Fn(El, f64, f64) + 'static) -> Self

Adds a resize callback via ResizeObserver. The callback is called on a resize with the element’s first block’s inline and block size as arguments (width and height for row layout, height and width for column layout).

Source

pub fn ref_on_resize(&self, cb: impl Fn(El, f64, f64) + 'static) -> &Self

Source

pub fn ref_listen( &self, event: &'static str, cb: impl FnMut(&Event) + 'static, ) -> &Self

Add a listener for an event. The listener will be detached when this element is dropped (removed from the tree).

Source

pub fn ref_replace(&self, other: Vec<El>)

Replace the element in its parent with zero or more new elements.

Source

pub fn raw(&self) -> Element

Get the wrapped web_sys element from the El.

Source

pub fn ptr_id(&self) -> usize

For debugging, an id based on pointer address

Source

pub fn weak(&self) -> WeakEl

Produce a weak reference to the element.

Trait Implementations§

Source§

impl Clone for El

Source§

fn clone(&self) -> El

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for El

§

impl !RefUnwindSafe for El

§

impl !Send for El

§

impl !Sync for El

§

impl Unpin for El

§

impl !UnwindSafe for El

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.