RespoElement

Struct RespoElement 

Source
pub struct RespoElement<T>
where T: Debug + Clone,
{ pub name: Rc<str>, pub attributes: 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

§attributes: HashMap<Rc<str>, String>§style: RespoStyle

inlines 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>
where T: Debug + Clone,

Source

pub fn named(name: &str) -> Self

Source

pub fn to_node(self) -> RespoNode<T>

Source

pub fn style(self, more: RespoStyle) -> Self

attach styles

element.style(respo_style().margin(10))
Source

pub fn modify_style<U>(self, builder: U) -> Self
where U: Fn(&mut RespoStyle),

imparative way of updating style

element.modify_style(|s| {
  if data > 1 {
    s.color(CssColor::Red);
  }
});
Source

pub fn attr<U, V>(self, property: U, value: V) -> Self
where U: Into<Rc<str>> + ToOwned, V: Display,

set an attribute on element

Source

pub fn maybe_attr<U, V>(self, property: U, value: Option<V>) -> Self
where U: Into<Rc<str>> + ToOwned, V: Display,

set an attribute on element, but using None indicates noting

Source

pub fn attrs<V>(self, list: &[(&str, V)]) -> Self
where V: AsRef<str>,

set attributes from list of string pairs

Source

pub fn on_click<U>(self, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

Source

pub fn on_input<U>(self, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

Source

pub fn on_keydown<U>(self, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

handle keydown event

Source

pub fn on_focus<U>(self, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

handle focus event

Source

pub fn on_change<U>(self, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

handle change event

Source

pub fn on_named_event<U>(self, name: &str, handler: U) -> Self
where U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,

attach a listener by event name(only a small set of events are supported)

Source

pub fn children<U>(self, more: U) -> Self
where U: IntoIterator<Item = RespoNode<T>>,

add children elements, index key are generated from index number

Source

pub fn children_indexed<U>(self, more: U) -> Self
where U: IntoIterator<Item = (RespoIndexKey, RespoNode<T>)>,

add children elements, with index keys specified

Source

pub fn elements<U>(self, mode: U) -> Self
where U: IntoIterator<Item = RespoElement<T>>,

add elements. if any component is involved, use self.children([]) instead

Source

pub fn class<U>(self, name: U) -> Self
where U: Into<String>,

attach a class name for adding styles

Source

pub fn maybe_class<U>(self, name: Option<U>) -> Self
where U: Into<String>,

attach an optional class name for adding styles

Source

pub fn toggle_class<U>(self, name: U, on: bool) -> Self
where U: Into<String>,

attach a class name, controlled by a boolean

Source

pub fn class_list<U>(self, names: &[U]) -> Self
where U: Into<String> + Clone,

attach a list of class names for adding styles

Source

pub fn inner_text<U>(self, content: U) -> Self
where U: Into<String>,

writes innerText

Source

pub fn inner_html<U>(self, content: U) -> Self
where U: Into<String>,

writes innerHTML

Source

pub fn value<U>(self, content: U) -> Self
where U: Into<String>,

writes value

Trait Implementations§

Source§

impl<T> Clone for RespoElement<T>
where T: Debug + Clone + Clone,

Source§

fn clone(&self) -> RespoElement<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for RespoElement<T>
where T: Debug + Clone + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<RespoElement<()>> for RespoNode<()>

Source§

fn from(el: RespoElement<()>) -> Self

Converts to this type from the input type.
Source§

impl<T> PartialEq for RespoElement<T>
where T: Debug + Clone + PartialEq,

Source§

fn eq(&self, other: &RespoElement<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Eq for RespoElement<T>
where T: Debug + Clone + Eq,

Source§

impl<T> StructuralPartialEq for RespoElement<T>
where T: Debug + Clone,

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.