wip: more examples

This commit is contained in:
Jonathan Kelley committed 2021-07-08 10:17:51 -04:00
1 parent e4cdb645aa
commit 2547da36a0
9 files changed
+166 -55

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
//! Example: Webview Renderer
//! -------------------------
//!
//! This example shows how to use the dioxus_webview crate to build a basic desktop application.
//!
//! Under the hood, the dioxus_webview crate bridges a native Dioxus VirtualDom with a custom prebuit application running
//! in the webview runtime. Custom handlers are provided for the webview instance to consume patches and emit user events
//! into the native VDom instance.
//!
//! Currently, NodeRefs won't work properly, but all other event functionality will.
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App, |c| c);
}
static App: FC<()> = |cx| {
let slide_id = use_state(cx, || 0);
let slide = match *slide_id {
0 => cx.render(rsx!(Title {})),
1 => cx.render(rsx!(Slide1 {})),
2 => cx.render(rsx!(Slide2 {})),
3 => cx.render(rsx!(Slide3 {})),
_ => cx.render(rsx!(End {})),
};
cx.render(rsx! {
div {
div {
div { h1 {"my awesome slideshow"} }
div {
button {"<-", onclick: move |_| if *slide_id != 0 { *slide_id.get_mut() -= 1}}
h3 { "{slide_id}" }
button {"->" onclick: move |_| if *slide_id != 4 { *slide_id.get_mut() += 1 }}
}
}
{slide}
}
})
};
const Title: FC<()> = |cx| {
cx.render(rsx! {
div {
}
})
};
const Slide1: FC<()> = |cx| {
cx.render(rsx! {
div {
}
})
};
const Slide2: FC<()> = |cx| {
cx.render(rsx! {
div {
}
})
};
const Slide3: FC<()> = |cx| {
cx.render(rsx! {
div {
}
})
};
const End: FC<()> = |cx| {
cx.render(rsx! {
div {
}
})
};
+2 -2
View File
@@ -16,7 +16,7 @@ fn main() {
}
static App: FC<()> = |cx| {
let (count, set_count) = use_state_classic(cx, || 0);
let mut count = use_state(cx, || 0);
cx.render(rsx! {
div {
@@ -24,7 +24,7 @@ static App: FC<()> = |cx| {
p { "Count is {count}" }
button {
"Click to increment"
onclick: move |_| set_count(count + 1)
onclick: move |_| count += 1
}
}
})