HtmlElement

Struct HtmlElement 

Source
pub struct HtmlElement<C> { /* private fields */ }
Expand description

A Generic html node with a given name.

Implementations§

Source§

impl<C> HtmlElement<C>

Source

pub fn new(tag: &'static str) -> Self

Create a new html element with the specific tag

All non-deprecated html elements have a helper function in this module

Source

pub fn on<E: Event>(self, function: impl EventHandler<C, E::JsEvent>) -> Self

Register a event handler for this element.

The event handler is a closure taking a mutable reference to S<Self>.

e::button().on("click", |ctx: &mut S<Self>| {
    *ctx.some_value += 1;
})

For more information see Reactivity in the book.

Source

pub fn child<E: Element<C> + 'static>(self, child: E) -> Self

Push a child to this element. This accepts any valid element including closures.

e::div()
    .child(e::h1().text("Wow!"))
    .child(|ctx: &S<Self>| {
        if *ctx.toggle {
            "Hello"
        } else {
            "World"
        }
    })
Source

pub fn text<E: Element<C>>(self, text: E) -> Self

This is a simple alias for child

Source

pub fn attr(self, key: &'static str, value: impl ToAttribute<C>) -> Self

Add a attribute to the node.

See Html Nodes in the book for the schematics of the various valid attribute types.

Source

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

Shorthand for .attr("id", ...) with a specific ID.

Source

pub fn class(self, class: &'static str) -> Self

Add a class to the element.

Trait Implementations§

Auto Trait Implementations§

§

impl<C> Freeze for HtmlElement<C>

§

impl<C> !RefUnwindSafe for HtmlElement<C>

§

impl<C> !Send for HtmlElement<C>

§

impl<C> !Sync for HtmlElement<C>

§

impl<C> Unpin for HtmlElement<C>

§

impl<C> !UnwindSafe for HtmlElement<C>

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, 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.