Skip to main content

Element

Struct Element 

Source
pub struct Element<T: Render> {
    pub is_fragment: bool,
    pub tag: String,
    pub attributes: BTreeMap<String, AttributeValue>,
    pub children: Option<T>,
    pub reff: Option<(String, String)>,
    pub onclick: Arc<Mutex<Option<OnClickClosure>>>,
}
Expand description

A single HTML element node carrying its tag, attributes, optional children and an optional click handler, used to build and render the DOM tree.

Fields§

§is_fragment: bool

When true, the element renders only its children without wrapping tags.

§tag: String

The element’s tag name (e.g. div, flow-select).

§attributes: BTreeMap<String, AttributeValue>

The element’s attributes keyed by name.

§children: Option<T>

The element’s child content, if any.

§reff: Option<(String, String)>

Optional @name binding as a (name, value) pair recorded in the hooks map.

§onclick: Arc<Mutex<Option<OnClickClosure>>>

Retained click-event closure shared across clones of this element.

Implementations§

Source§

impl<T: Render + Clone + 'static> Element<T>

Source

pub fn on(self, name: &str, cb: Box<dyn Fn(MouseEvent, WebElement)>) -> Self

Registers an event callback on this element. Currently only the "click" event is wired up, attaching cb as a retained closure that receives the mouse event and the target WebElement.

Trait Implementations§

Source§

impl<T: Clone + Render> Clone for Element<T>

Source§

fn clone(&self) -> Element<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Render> Debug for Element<T>

Source§

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

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

impl<T: Default + Render> Default for Element<T>

Source§

fn default() -> Element<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Render + Clone + 'static> Render for Element<T>

Source§

fn render_node( self, parent: &mut WebElement, map: &mut Hooks, renderables: &mut Renderables, ) -> ElementResult<()>

Builds the live DOM nodes for this value under _parent, recording any @name hooks into _map and pushing retained renderables onto _renderables. The default implementation does nothing.
Source§

fn render(&self, w: &mut Vec<String>) -> ElementResult<()>

Renders this value as HTML markup, appending fragments to _w.
Source§

fn remove_event_listeners(&self) -> ElementResult<()>

Releases any retained event-listener closures held by this value and its children. The default implementation does nothing.
Source§

fn html(&self) -> String

Renders this value to an HTML string by concatenating its markup fragments.
Source§

fn render_tree(self) -> ElementResult<Html>
where Self: Sized,

Renders this value into a detached container and returns an Html holding the resulting root elements, hooks and retained renderables.
Source§

fn render_tree_into( self, parent: &mut Element, renderables: &mut Renderables, ) -> ElementResult<BTreeMap<String, Element>>
where Self: Sized,

Renders this value’s DOM nodes into the existing parent element, collecting retained renderables and returning the resulting map of @name hook bindings.

Auto Trait Implementations§

§

impl<T> !Send for Element<T>

§

impl<T> !Sync for Element<T>

§

impl<T> Freeze for Element<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Element<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Element<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Element<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Element<T>
where T: UnwindSafe,

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more