slideshow.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //! Example: Webview Renderer
  2. //! -------------------------
  3. //!
  4. //! This example shows how to use the dioxus_webview crate to build a basic desktop application.
  5. //!
  6. //! Under the hood, the dioxus_webview crate bridges a native Dioxus VirtualDom with a custom prebuit application running
  7. //! in the webview runtime. Custom handlers are provided for the webview instance to consume patches and emit user events
  8. //! into the native VDom instance.
  9. //!
  10. //! Currently, NodeRefs won't work properly, but all other event functionality will.
  11. use dioxus::prelude::*;
  12. fn main() {
  13. dioxus::desktop::launch(App, |c| c);
  14. }
  15. static App: FC<()> = |cx| {
  16. let slide_id = use_state(cx, || 0);
  17. let slide = match *slide_id {
  18. 0 => cx.render(rsx!(Title {})),
  19. 1 => cx.render(rsx!(Slide1 {})),
  20. 2 => cx.render(rsx!(Slide2 {})),
  21. 3 => cx.render(rsx!(Slide3 {})),
  22. _ => cx.render(rsx!(End {})),
  23. };
  24. cx.render(rsx! {
  25. div {
  26. div {
  27. div { h1 {"my awesome slideshow"} }
  28. div {
  29. button {"<-", onclick: move |_| if *slide_id != 0 { *slide_id.get_mut() -= 1}}
  30. h3 { "{slide_id}" }
  31. button {"->" onclick: move |_| if *slide_id != 4 { *slide_id.get_mut() += 1 }}
  32. }
  33. }
  34. {slide}
  35. }
  36. })
  37. };
  38. const Title: FC<()> = |cx| {
  39. cx.render(rsx! {
  40. div {
  41. }
  42. })
  43. };
  44. const Slide1: FC<()> = |cx| {
  45. cx.render(rsx! {
  46. div {
  47. }
  48. })
  49. };
  50. const Slide2: FC<()> = |cx| {
  51. cx.render(rsx! {
  52. div {
  53. }
  54. })
  55. };
  56. const Slide3: FC<()> = |cx| {
  57. cx.render(rsx! {
  58. div {
  59. }
  60. })
  61. };
  62. const End: FC<()> = |cx| {
  63. cx.render(rsx! {
  64. div {
  65. }
  66. })
  67. };