2022-01-17 04:27:41 +08:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2022-01-10 15:57:03 +08:00
|
|
|
//! Example: README.md showcase
|
|
|
|
//!
|
|
|
|
//! The example from the README.md.
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-10 03:15:20 +08:00
|
|
|
dioxus_desktop::launch(app);
|
2022-01-10 15:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx! {
|
|
|
|
Button {
|
|
|
|
a: "asd".to_string(),
|
2022-03-16 14:36:39 +08:00
|
|
|
c: "asd".to_string(),
|
|
|
|
d: Some("asd".to_string()),
|
2022-01-17 04:27:41 +08:00
|
|
|
e: "asd".to_string(),
|
2022-01-10 15:57:03 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-16 14:36:39 +08:00
|
|
|
type SthElse<T> = Option<T>;
|
|
|
|
|
2022-01-10 15:57:03 +08:00
|
|
|
#[derive(Props, PartialEq)]
|
|
|
|
struct ButtonProps {
|
|
|
|
a: String,
|
|
|
|
|
|
|
|
#[props(default)]
|
2022-03-16 14:36:39 +08:00
|
|
|
b: String,
|
2022-01-10 15:57:03 +08:00
|
|
|
|
|
|
|
c: Option<String>,
|
|
|
|
|
2022-03-16 14:36:39 +08:00
|
|
|
#[props(!optional)]
|
2022-01-10 15:57:03 +08:00
|
|
|
d: Option<String>,
|
2022-01-17 04:27:41 +08:00
|
|
|
|
|
|
|
#[props(optional)]
|
2022-03-16 14:36:39 +08:00
|
|
|
e: SthElse<String>,
|
2022-01-10 15:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Button(cx: Scope<ButtonProps>) -> Element {
|
2022-01-17 04:27:41 +08:00
|
|
|
cx.render(rsx! {
|
|
|
|
button {
|
2022-03-16 14:36:39 +08:00
|
|
|
"{cx.props.a} | "
|
|
|
|
"{cx.props.b:?} | "
|
|
|
|
"{cx.props.c:?} | "
|
|
|
|
"{cx.props.d:?} | "
|
2022-01-17 04:27:41 +08:00
|
|
|
"{cx.props.e:?}"
|
|
|
|
}
|
|
|
|
})
|
2022-01-10 15:57:03 +08:00
|
|
|
}
|