[][src]Struct mt_dom::Element

pub struct Element<NS, TAG, ATT, VAL, EVENT, MSG> {
    pub namespace: Option<NS>,
    pub tag: TAG,
    pub attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>,
    pub children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>,
    pub self_closing: bool,
}

Represents an element of the virtual node An element has a generic tag, this tag could be a static str tag, such as usage in html dom. Example of which are div, a, input, img, etc.

Tag is a generic type, which can represent a different DOM tree other than the html dom such as widgets in native platform such as gtk, example of which are Hpane, Vbox, Image,

An element can have an optional namespace, such in the case for html dom where namespace like HTML and SVG, which needs to specified in order to create the DOM element to work on the browser.

The namespace is also needed in attributes where namespace are necessary such as xlink:href where the namespace xlink is needed in order for the linked element in an svg image to work.

Fields

namespace: Option<NS>

namespace of this element, svg elements requires namespace to render correcly in the browser

tag: TAG

the element tag, such as div, a, button

attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>

attributes for this element

children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>

children elements of this element

self_closing: bool

is the element has a self closing tag

Implementations

impl<NS, TAG, ATT, VAL, EVENT, MSG> Element<NS, TAG, ATT, VAL, EVENT, MSG>[src]

pub fn new(
    namespace: Option<NS>,
    tag: TAG,
    attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>,
    children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>,
    self_closing: bool
) -> Self
[src]

create a new instance of an element

pub fn add_attributes(
    &mut self,
    attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>
)
[src]

add attributes to this element

pub fn add_children(
    &mut self,
    children: Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>
)
[src]

add children virtual node to this element

pub fn get_children(&self) -> &[Node<NS, TAG, ATT, VAL, EVENT, MSG>][src]

returns a refernce to the children of this node

pub fn children_mut(&mut self) -> &mut [Node<NS, TAG, ATT, VAL, EVENT, MSG>][src]

returns a mutable reference to the children of this node

pub fn take_children(self) -> Vec<Node<NS, TAG, ATT, VAL, EVENT, MSG>>[src]

consume self and return the children

pub fn get_attributes(&self) -> &[Attribute<NS, ATT, VAL, EVENT, MSG>][src]

return a reference to the attribute of this element

pub fn take_attributes(self) -> Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>[src]

consume self and return the attributes

pub fn namespace(&self) -> Option<&NS>[src]

return the namespace of this element

pub fn tag(&self) -> &TAG[src]

return the tag of this element

pub fn take_tag(self) -> TAG[src]

consume self and return the tag of this element

pub fn set_tag(&mut self, tag: TAG)[src]

change the tag of this element

impl<NS, TAG, ATT, VAL, EVENT, MSG> Element<NS, TAG, ATT, VAL, EVENT, MSG> where
    ATT: PartialEq
[src]

Note: using the #[derive(PartialEq)] needs EVENT and MSG to also be PartialEq.

The reason this is manually implemented is, so that EVENT and MSG doesn't need to be PartialEq as it is part of the Callback objects and are not compared

pub fn remove_attribute(&mut self, key: &ATT)[src]

remove the attributes with this key

pub fn set_attributes(
    &mut self,
    attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>
)
[src]

remove the existing values of this attribute and add the new values

pub fn merge_attributes(
    &mut self,
    new_attrs: Vec<Attribute<NS, ATT, VAL, EVENT, MSG>>
)
[src]

merge to existing attributes if it exist

pub fn get_attribute_value(&self, name: &ATT) -> Option<Vec<&VAL>>[src]

return all the attribute values which the name &ATT

impl<NS, TAG, ATT, VAL, EVENT, MSG> Element<NS, TAG, ATT, VAL, EVENT, MSG> where
    EVENT: 'static,
    MSG: 'static, 
[src]

pub fn map_callback<MSG2>(
    self,
    cb: Callback<MSG, MSG2>
) -> Element<NS, TAG, ATT, VAL, EVENT, MSG2> where
    MSG2: 'static, 
[src]

map_callback the return of the callback from MSG to MSG2

Trait Implementations

impl<NS, TAG, ATT, VAL, EVENT, MSG> Clone for Element<NS, TAG, ATT, VAL, EVENT, MSG> where
    NS: Clone,
    TAG: Clone,
    ATT: Clone,
    VAL: Clone
[src]

impl<NS, TAG, ATT, VAL, EVENT, MSG> Debug for Element<NS, TAG, ATT, VAL, EVENT, MSG> where
    NS: Debug,
    TAG: Debug,
    ATT: Debug,
    VAL: Debug
[src]

Note: using the #[derive(Debug)] needs EVENT and MSG to also be Debug

The reason this is manually implemented is, so that EVENT and MSG doesn't need to be Debug as it is part of the Callback objects and are not shown.

impl<NS: Default, TAG: Default, ATT: Default, VAL: Default, EVENT: Default, MSG: Default> Default for Element<NS, TAG, ATT, VAL, EVENT, MSG>[src]

impl<NS: PartialEq, TAG: PartialEq, ATT: PartialEq, VAL: PartialEq, EVENT: PartialEq, MSG: PartialEq> PartialEq<Element<NS, TAG, ATT, VAL, EVENT, MSG>> for Element<NS, TAG, ATT, VAL, EVENT, MSG>[src]

impl<NS, TAG, ATT, VAL, EVENT, MSG> StructuralPartialEq for Element<NS, TAG, ATT, VAL, EVENT, MSG>[src]

Auto Trait Implementations

impl<NS, TAG, ATT, VAL, EVENT, MSG> !RefUnwindSafe for Element<NS, TAG, ATT, VAL, EVENT, MSG>

impl<NS, TAG, ATT, VAL, EVENT, MSG> !Send for Element<NS, TAG, ATT, VAL, EVENT, MSG>

impl<NS, TAG, ATT, VAL, EVENT, MSG> !Sync for Element<NS, TAG, ATT, VAL, EVENT, MSG>

impl<NS, TAG, ATT, VAL, EVENT, MSG> Unpin for Element<NS, TAG, ATT, VAL, EVENT, MSG> where
    ATT: Unpin,
    NS: Unpin,
    TAG: Unpin,
    VAL: Unpin

impl<NS, TAG, ATT, VAL, EVENT, MSG> !UnwindSafe for Element<NS, TAG, ATT, VAL, EVENT, MSG>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.