Struct respo::RespoElement
source · pub struct RespoElement<T>{
pub name: Rc<str>,
pub attrs: HashMap<Rc<str>, String>,
pub style: RespoStyle,
pub children: Vec<(RespoIndexKey, RespoNode<T>)>,
/* private fields */
}Expand description
internal abstraction for an element
Fields§
§name: Rc<str>tagName
attrs: HashMap<Rc<str>, String>§style: RespoStyleinlines styles, partially typed.
there’s also a macro called static_styles for inserting CSS rules
children: Vec<(RespoIndexKey, RespoNode<T>)>each child as a key like a string, by default generated from index, they are used in diffing, so it’s better to be distinct, although not required to be.
Implementations§
source§impl<T> RespoElement<T>
impl<T> RespoElement<T>
pub fn named(name: &str) -> Self
pub fn to_node(self) -> RespoNode<T>
sourcepub fn style(self, more: RespoStyle) -> Self
pub fn style(self, more: RespoStyle) -> Self
attach styles
element.style(RespoStyle::default().margin(10))sourcepub fn modify_style<U>(self, builder: U) -> Selfwhere
U: Fn(&mut RespoStyle),
pub fn modify_style<U>(self, builder: U) -> Selfwhere
U: Fn(&mut RespoStyle),
imparative way of updating style
element.modify_style(|s| {
if data > 1 {
s.color(CssColor::Red);
}
});sourcepub fn maybe_attribute<U, V>(self, property: U, value: Option<V>) -> Self
pub fn maybe_attribute<U, V>(self, property: U, value: Option<V>) -> Self
set an attribute on element, but using None indicates noting
pub fn on_click<U>(self, handler: U) -> Self
pub fn on_input<U>(self, handler: U) -> Self
sourcepub fn on_keydown<U>(self, handler: U) -> Self
pub fn on_keydown<U>(self, handler: U) -> Self
handle keydown event
sourcepub fn on_named_event<U>(self, name: &str, handler: U) -> Self
pub fn on_named_event<U>(self, name: &str, handler: U) -> Self
attach a listener by event name(only a small set of events are supported)
sourcepub fn children<U>(self, more: U) -> Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
pub fn children<U>(self, more: U) -> Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
add children elements, index key are generated from index number
sourcepub fn children_indexed<U>(self, more: U) -> Self
pub fn children_indexed<U>(self, more: U) -> Self
add children elements, with index keys specified
sourcepub fn elements<U>(self, mode: U) -> Selfwhere
U: IntoIterator<Item = RespoElement<T>>,
pub fn elements<U>(self, mode: U) -> Selfwhere
U: IntoIterator<Item = RespoElement<T>>,
add elements. if any component is involved, use self.children([]) instead
sourcepub fn maybe_class<U>(self, name: Option<U>) -> Self
pub fn maybe_class<U>(self, name: Option<U>) -> Self
attach an optional class name for adding styles
sourcepub fn toggle_class<U>(self, name: U, on: bool) -> Self
pub fn toggle_class<U>(self, name: U, on: bool) -> Self
attach a class name, controlled by a boolean
sourcepub fn class_list<U>(self, names: &[U]) -> Self
pub fn class_list<U>(self, names: &[U]) -> Self
attach a list of class names for adding styles
sourcepub fn inner_text<U>(self, content: U) -> Self
pub fn inner_text<U>(self, content: U) -> Self
writes innerText
sourcepub fn inner_html<U>(self, content: U) -> Self
pub fn inner_html<U>(self, content: U) -> Self
writes innerHTML
Trait Implementations§
source§impl<T> Clone for RespoElement<T>
impl<T> Clone for RespoElement<T>
source§fn clone(&self) -> RespoElement<T>
fn clone(&self) -> RespoElement<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T> Debug for RespoElement<T>
impl<T> Debug for RespoElement<T>
source§impl From<RespoElement<()>> for RespoNode<()>
impl From<RespoElement<()>> for RespoNode<()>
source§fn from(el: RespoElement<()>) -> Self
fn from(el: RespoElement<()>) -> Self
source§impl<T> PartialEq for RespoElement<T>
impl<T> PartialEq for RespoElement<T>
impl<T> Eq for RespoElement<T>
impl<T> StructuralPartialEq for RespoElement<T>
Auto Trait Implementations§
impl<T> Freeze for RespoElement<T>
impl<T> !RefUnwindSafe for RespoElement<T>
impl<T> !Send for RespoElement<T>
impl<T> !Sync for RespoElement<T>
impl<T> Unpin for RespoElement<T>
impl<T> !UnwindSafe for RespoElement<T>
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)