pub struct Element<MSG> {
pub namespace: Option<&'static str>,
pub tag: &'static str,
pub self_closing: bool,
/* private fields */
}
Expand description
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<&'static str>
namespace of this element, svg elements requires namespace to render correcly in the browser
tag: &'static str
the element tag, such as div, a, button
self_closing: bool
is the element has a self closing tag
Implementations§
source§impl<MSG> Element<MSG>
impl<MSG> Element<MSG>
sourcepub fn new(
namespace: Option<&'static str>,
tag: &'static str,
attrs: impl IntoIterator<Item = Attribute<MSG>>,
children: impl IntoIterator<Item = Node<MSG>>,
self_closing: bool
) -> Element<MSG>
pub fn new( namespace: Option<&'static str>, tag: &'static str, attrs: impl IntoIterator<Item = Attribute<MSG>>, children: impl IntoIterator<Item = Node<MSG>>, self_closing: bool ) -> Element<MSG>
create a new instance of an element
sourcepub fn add_attributes(
&mut self,
attrs: impl IntoIterator<Item = Attribute<MSG>>
)
pub fn add_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<MSG>> )
add attributes to this element
sourcepub fn add_children(&mut self, children: impl IntoIterator<Item = Node<MSG>>)
pub fn add_children(&mut self, children: impl IntoIterator<Item = Node<MSG>>)
add children virtual node to this element
sourcepub fn children_mut(&mut self) -> &mut [Node<MSG>]
pub fn children_mut(&mut self) -> &mut [Node<MSG>]
returns a mutable reference to the children of this node
sourcepub fn swap_remove_child(&mut self, index: usize) -> Node<MSG>
pub fn swap_remove_child(&mut self, index: usize) -> Node<MSG>
Removes an child node from this element and returns it.
The removed child is replaced by the last child of the element’s children.
§Panics
Panics if index is out of bounds in children
sourcepub fn swap_children(&mut self, a: usize, b: usize)
pub fn swap_children(&mut self, a: usize, b: usize)
sourcepub fn take_children(self) -> Vec<Node<MSG>>
pub fn take_children(self) -> Vec<Node<MSG>>
consume self and return the children
sourcepub fn attributes(&self) -> &[Attribute<MSG>]
pub fn attributes(&self) -> &[Attribute<MSG>]
return a reference to the attribute of this element
sourcepub fn take_attributes(self) -> Vec<Attribute<MSG>>
pub fn take_attributes(self) -> Vec<Attribute<MSG>>
consume self and return the attributes
sourcepub fn remove_attribute(&mut self, name: &&'static str)
pub fn remove_attribute(&mut self, name: &&'static str)
remove the attributes with this key
sourcepub fn set_attributes(
&mut self,
attrs: impl IntoIterator<Item = Attribute<MSG>>
)
pub fn set_attributes( &mut self, attrs: impl IntoIterator<Item = Attribute<MSG>> )
remove the existing values of this attribute and add the new values
sourcepub fn merge_attributes(
&mut self,
new_attrs: impl IntoIterator<Item = Attribute<MSG>>
)
pub fn merge_attributes( &mut self, new_attrs: impl IntoIterator<Item = Attribute<MSG>> )
merge to existing attributes if it exist
sourcepub fn attribute_value(
&self,
name: &&'static str
) -> Option<Vec<&AttributeValue<MSG>>>
pub fn attribute_value( &self, name: &&'static str ) -> Option<Vec<&AttributeValue<MSG>>>
return all the attribute values which the name &AttributeName
sourcepub fn first_value(&self, att_name: &&'static str) -> Option<&Value>
pub fn first_value(&self, att_name: &&'static str) -> Option<&Value>
get the first value of the attribute which has the name att_name
of this element
sourcepub fn group_indexed_attributes_per_name<'a>(
attrs: &'a [Attribute<MSG>]
) -> IndexMap<&'a &'static str, Vec<(usize, &'a Attribute<MSG>)>>
pub fn group_indexed_attributes_per_name<'a>( attrs: &'a [Attribute<MSG>] ) -> IndexMap<&'a &'static str, Vec<(usize, &'a Attribute<MSG>)>>
grouped the attributes, but retain the index of the attribute relative to its location in the element
sourcepub fn has_mount_callback(&self) -> bool
pub fn has_mount_callback(&self) -> bool
return true if this element has a mount callback
Trait Implementations§
source§impl<MSG> PartialEq for Element<MSG>
impl<MSG> PartialEq for Element<MSG>
impl<MSG> Eq for Element<MSG>
Auto Trait Implementations§
impl<MSG> Freeze for Element<MSG>
impl<MSG> !RefUnwindSafe for Element<MSG>
impl<MSG> !Send for Element<MSG>
impl<MSG> !Sync for Element<MSG>
impl<MSG> Unpin for Element<MSG>
impl<MSG> !UnwindSafe for Element<MSG>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.