pub enum Node<T, ATT, EVENT, MSG>where
MSG: 'static,
EVENT: 'static,
ATT: Clone,{
Element(Element<T, ATT, EVENT, MSG>),
Text(Text),
}
Expand description
This is the core data structure of the library.
Any tree can be represented by Node
.
The T
is generic instead of just using plain &'static str
in order for this library to be used not only in html based widget
but can also be used to represent native GUI widgets
in various platforms.
Note: Clone is necessary for the aesthetics in the construction of node through series of function calls. Without Clone, the user code would look like these:
div(&[class("some-class"), &[text("Some text")])
as compared to
div([class("some-class"), [text("some text)])
Cloning is only done once, and happens when constructing the views into a node tree. Cloning also allows flexibility such as adding more children into an existing node/element.
Variants§
Element(Element<T, ATT, EVENT, MSG>)
Element variant of a virtual node
Text(Text)
Text variant of a virtual node
Implementations§
Source§impl<T, ATT, EVENT, MSG> Node<T, ATT, EVENT, MSG>
impl<T, ATT, EVENT, MSG> Node<T, ATT, EVENT, MSG>
Sourcepub fn map_msg<F, MSG2>(self, func: F) -> Node<T, ATT, EVENT, MSG2>where
F: Fn(MSG) -> MSG2 + 'static,
MSG2: 'static,
pub fn map_msg<F, MSG2>(self, func: F) -> Node<T, ATT, EVENT, MSG2>where
F: Fn(MSG) -> MSG2 + 'static,
MSG2: 'static,
map the msg of callback of this element node
Sourcepub fn take_element(self) -> Option<Element<T, ATT, EVENT, MSG>>
pub fn take_element(self) -> Option<Element<T, ATT, EVENT, MSG>>
consume the element
Sourcepub fn as_element_mut(&mut self) -> Option<&mut Element<T, ATT, EVENT, MSG>>
pub fn as_element_mut(&mut self) -> Option<&mut Element<T, ATT, EVENT, MSG>>
Get a mutable reference to the element, if this node is an element node
Sourcepub fn as_element_ref(&self) -> Option<&Element<T, ATT, EVENT, MSG>>
pub fn as_element_ref(&self) -> Option<&Element<T, ATT, EVENT, MSG>>
returns a reference to the element if this is an element node
Sourcepub fn add_children(self, children: Vec<Node<T, ATT, EVENT, MSG>>) -> Self
pub fn add_children(self, children: Vec<Node<T, ATT, EVENT, MSG>>) -> Self
Append children to this element
Sourcepub fn add_attributes(self, attributes: Vec<Attribute<ATT, EVENT, MSG>>) -> Self
pub fn add_attributes(self, attributes: Vec<Attribute<ATT, EVENT, MSG>>) -> Self
add attributes to the node and returns itself this is used in view building
Sourcepub fn add_attributes_ref_mut(
&mut self,
attributes: Vec<Attribute<ATT, EVENT, MSG>>,
)
pub fn add_attributes_ref_mut( &mut self, attributes: Vec<Attribute<ATT, EVENT, MSG>>, )
add attributes using a mutable reference to self
Sourcepub fn get_attributes(&self) -> Vec<Attribute<ATT, EVENT, MSG>>
pub fn get_attributes(&self) -> Vec<Attribute<ATT, EVENT, MSG>>
get the attributes of this node
Sourcepub fn eldest_child_text(&self) -> Option<&str>
pub fn eldest_child_text(&self) -> Option<&str>
returns the text if this node has only one child and is a text. includes: h1, h2..h6, p,
Sourcepub fn get_children(&self) -> Option<&[Node<T, ATT, EVENT, MSG>]>
pub fn get_children(&self) -> Option<&[Node<T, ATT, EVENT, MSG>]>
return the children of this node if it is an element