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
impl El
pub fn ref_text(&self, text: &str) -> &Self
Sourcepub fn attr(self, key: &str, value: &str) -> Self
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.
pub fn ref_attr(&self, key: &str, value: &str) -> &Self
Sourcepub fn ref_remove_attr(&self, key: &str) -> &Self
pub fn ref_remove_attr(&self, key: &str) -> &Self
Remove an attribute from the element.
pub fn ref_classes(&self, keys: &[&str]) -> &Self
Sourcepub fn ref_remove_classes(&self, keys: &[&str]) -> &Self
pub fn ref_remove_classes(&self, keys: &[&str]) -> &Self
Remove (if not existing) all of the listed keys.
pub fn ref_modify_classes(&self, keys: &[(&str, bool)]) -> &Self
pub fn ref_push(&self, add: El) -> &Self
pub fn ref_extend(&self, add: Vec<El>) -> &Self
Sourcepub fn ref_splice(&self, offset: usize, remove: usize, add: Vec<El>) -> &Self
pub fn ref_splice(&self, offset: usize, remove: usize, add: Vec<El>) -> &Self
Add and remove multiple elements.
Sourcepub fn own<T: 'static>(self, supplier: impl FnOnce(&El) -> T) -> Self
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.
pub fn ref_own<T: 'static>(&self, supplier: impl FnOnce(&El) -> T) -> &Self
pub fn on(self, event: &'static str, cb: impl FnMut(&Event) + 'static) -> Self
pub fn on_with_options( self, event: &'static str, opts: EventListenerOptions, cb: impl FnMut(&Event) + 'static, ) -> Self
pub fn ref_on( &self, event: &'static str, cb: impl FnMut(&Event) + 'static, ) -> &Self
pub fn ref_on_with_options( &self, event: &'static str, opts: EventListenerOptions, cb: impl FnMut(&Event) + 'static, ) -> &Self
Sourcepub fn on_resize(self, cb: impl Fn(El, f64, f64) + 'static) -> Self
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).
pub fn ref_on_resize(&self, cb: impl Fn(El, f64, f64) + 'static) -> &Self
Sourcepub fn ref_listen(
&self,
event: &'static str,
cb: impl FnMut(&Event) + 'static,
) -> &Self
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).
Sourcepub fn ref_replace(&self, other: Vec<El>)
pub fn ref_replace(&self, other: Vec<El>)
Replace the element in its parent with zero or more new elements.