dioxus/examples/simple_desktop.rs

82 lines
1.9 KiB
Rust
Raw Normal View History

2022-12-16 10:55:20 +00:00
#![allow(non_snake_case)]
2022-12-13 02:31:30 +00:00
use dioxus::prelude::*;
2022-12-16 10:55:20 +00:00
use dioxus_router::prelude::*;
2022-12-13 02:31:30 +00:00
fn main() {
simple_logger::SimpleLogger::new()
.with_level(log::LevelFilter::Debug)
.with_module_level("dioxus", log::LevelFilter::Trace)
.init()
.unwrap();
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
2023-06-02 17:33:47 +00:00
render! {
Router {}
}
}
2022-12-16 10:55:20 +00:00
2023-06-02 17:33:47 +00:00
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(NavBar)]
#[route("/")]
Home {},
#[nest("/new")]
#[route("/")]
BlogList {},
#[route("/:post")]
BlogPost {
post: String,
},
#[end_nest]
#[route("/oranges")]
Oranges {},
}
#[inline_props]
fn NavBar(cx: Scope) -> Element {
2022-12-16 10:55:20 +00:00
render! {
h1 { "Your app here" }
ul {
2023-06-02 17:33:47 +00:00
li { Link { target: Route::Home {}, "home" } }
li { Link { target: Route::BlogList {}, "blog" } }
li { Link { target: Route::BlogPost { post: "tim".into() }, "tims' blog" } }
li { Link { target: Route::BlogPost { post: "bill".into() }, "bills' blog" } }
li { Link { target: Route::BlogPost { post: "james".into() }, "james amazing' blog" } }
2022-12-13 02:31:30 +00:00
}
2023-06-02 17:33:47 +00:00
Outlet {}
2022-12-16 10:55:20 +00:00
}
2022-12-13 02:31:30 +00:00
}
2023-06-02 17:33:47 +00:00
#[inline_props]
2022-12-13 02:31:30 +00:00
fn Home(cx: Scope) -> Element {
log::debug!("rendering home {:?}", cx.scope_id());
2022-12-16 10:55:20 +00:00
render! { h1 { "Home" } }
2022-12-13 02:31:30 +00:00
}
2023-06-02 17:33:47 +00:00
#[inline_props]
2022-12-13 02:31:30 +00:00
fn BlogList(cx: Scope) -> Element {
log::debug!("rendering blog list {:?}", cx.scope_id());
2022-12-16 10:55:20 +00:00
render! { div { "Blog List" } }
2022-12-13 02:31:30 +00:00
}
2023-06-02 17:33:47 +00:00
#[inline_props]
fn BlogPost(cx: Scope, post: String) -> Element {
log::debug!("rendering blog post {}", post);
2022-12-13 02:31:30 +00:00
2022-12-16 10:55:20 +00:00
render! {
2022-12-13 22:44:47 +00:00
div {
2023-06-02 17:33:47 +00:00
h3 { "blog post: {post}" }
Link { target: Route::BlogList {}, "back to blog list" }
2022-12-13 22:44:47 +00:00
}
2022-12-16 10:55:20 +00:00
}
}
2023-06-02 17:33:47 +00:00
#[inline_props]
2022-12-16 10:55:20 +00:00
fn Oranges(cx: Scope) -> Element {
render!("Oranges are not apples!")
2022-12-13 02:31:30 +00:00
}