[−][src]Struct valerie::Tag
An HTML Tag
Macros are defined for easier use of few tags. Can also be used to make other tags also.
Implementations
impl<T> Tag<T> where
T: JsCast,
T: AsRef<Element>,
[src]
T: JsCast,
T: AsRef<Element>,
pub fn new(tag: &'static str) -> Self
[src]
Make a new Tag
.
You have to specify the Element type i.e. Element
or HtmlDivElement
etc.
Examples
Tag::<web_sys::Element>::new("div").push("Hello, World!")
impl<T> Tag<T> where
T: AsRef<Node>,
[src]
T: AsRef<Node>,
pub fn push<U>(self, component: U) -> Self where
U: Component,
[src]
U: Component,
pub fn push_multiple<U>(self, components: &[U]) -> Self where
U: AsRef<Node>,
[src]
U: AsRef<Node>,
Push multiple components.
Rarely used. Use push
preferably.
Examples
div!().push_multiple(&[Node::from("Hello, "), Node::from("World!")])
pub fn push_loop<F, U>(self, n: usize, func: F) -> Self where
F: Fn(usize) -> U,
U: Component,
[src]
F: Fn(usize) -> U,
U: Component,
impl<T> Tag<T> where
T: AsRef<Node> + Clone + 'static,
[src]
T: AsRef<Node> + Clone + 'static,
pub fn on_event<F, U>(self, event: impl AsRef<str>, var: U, func: F) -> Self where
U: 'static,
F: FnMut(&mut U, &mut T) + 'static,
[src]
U: 'static,
F: FnMut(&mut U, &mut T) + 'static,
Attach an event to the Tag
.
Examples
let message = StateMutex::new(String::new()); button!(message.clone()) .on_event("mouseover", message.clone(), |x, _| { x.put("Mouse pointer is in me".to_string()) }) .on_event("mouseout", message.clone(), |x, _| { x.put("Mouse pointer is outside".to_string()) }) .on_event("mousedown", message.clone(), |x, _| { x.put("Mouse button pressed".to_string()) })
impl<T> Tag<T> where
T: AsRef<Element>,
[src]
T: AsRef<Element>,
pub fn id(self, id: impl AsRef<str>) -> Self
[src]
pub fn get_id(&self) -> String
[src]
Get the id of the Tag
.
Examples
let heading = h1!("Hello, World!").id("hello-world-id"); div!(heading.clone(), br!(), "id ", heading.get_id())
pub fn class(self, class: impl AsRef<str>) -> Self
[src]
pub fn get_class(&self) -> String
[src]
Get the class of the Tag
.
Examples
let heading = h1!("Hello, World!").class("heading"); div!(heading.clone(), br!(), "class ", heading.get_class())
pub fn attr(self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self
[src]
Set the attribute of the Tag
by key and value.
Examples
div!("Hello, World!") .attr("id", "hello-world")
pub fn get_attr(&self, key: impl AsRef<str>) -> Option<String>
[src]
Get the attribute of the Tag
by key.
Examples
let heading = h1!("Hello, World!").attr("id", "hello-world"); div!( heading.clone(), br!(), "attr ", heading.get_attr("id").unwrap() )
impl Tag<HtmlInputElement>
[src]
pub fn bind<T>(self, var: T) -> Self where
T: StateTrait + 'static,
T::Value: FromStr + Default,
[src]
T: StateTrait + 'static,
T::Value: FromStr + Default,
One way bind to the input element. Any change in the state variable won't be reflected back to the input element.
Examples
let state = StateMutex::new(String::new()); div!( state.clone(), br!(), input!("text").bind(state.clone()), input!("text").bind(state) )
pub fn double_bind<T>(self, var: T) -> Self where
T: StateTrait + 'static,
T::Value: FromStr + Default,
T::Channel: Deref<Target = String>,
[src]
T: StateTrait + 'static,
T::Value: FromStr + Default,
T::Channel: Deref<Target = String>,
Two way bind to the input element. Any change in the state variable will be reflected back to the input element.
Examples
let state = StateMutex::new(String::new()); div!( state.clone(), br!(), input!("text").double_bind(state.clone()), input!("text").double_bind(state) )
pub fn bind_func<T, F>(self, var: T, func: F) -> Self where
T: StateTrait + 'static,
F: FnOnce(String) -> T::Value,
F: 'static + Copy,
[src]
T: StateTrait + 'static,
F: FnOnce(String) -> T::Value,
F: 'static + Copy,
A function to bind to the input element.
This function gets called every time the event input
fires i.e. when the user enters and input.
Examples
let state = StateAtomic::new(0usize); div!( state.clone(), br!(), input!("text").bind_func(state, |x| x.len()) )
pub fn placeholder(self, text: impl AsRef<str>) -> Self
[src]
To add placeholder for the input element.
Examples
input!("text") .placeholder("Enter something...")
Trait Implementations
impl<T> AsRef<Node> for Tag<T> where
T: JsCast,
[src]
T: JsCast,
impl<T: Clone> Clone for Tag<T>
[src]
impl<T> Component for Tag<T> where
T: JsCast,
[src]
T: JsCast,
impl<T> Deref for Tag<T>
[src]
impl<T> DerefMut for Tag<T>
[src]
impl<T> From<Tag<T>> for Node where
T: JsCast,
[src]
T: JsCast,
impl<T> From<Tag<T>> for Node where
T: JsCast,
[src]
T: JsCast,
Auto Trait Implementations
impl<T> RefUnwindSafe for Tag<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Tag<T> where
T: Send,
T: Send,
impl<T> Sync for Tag<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Tag<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Tag<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,