btns.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //! Example: Webview Renderer
  2. //! -------------------------
  3. //!
  4. //! This example shows how to use the dioxus_desktop crate to build a basic desktop application.
  5. //!
  6. //! Under the hood, the dioxus_desktop 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. use dioxus_core as dioxus;
  13. use dioxus_hooks::*;
  14. use dioxus_html as dioxus_elements;
  15. // #[cfg]
  16. fn main() {
  17. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  18. dioxus_web::launch(App, |c| c);
  19. // env_logger::init();
  20. // dioxus::web::launch(App, |c| c);
  21. }
  22. static App: FC<()> = |cx| {
  23. dbg!("rednering parent");
  24. cx.render(rsx! {
  25. div {
  26. But {
  27. h1 {"he"}
  28. }
  29. // But {
  30. // h1 {"llo"}
  31. // }
  32. // But {
  33. // h1 {"world"}
  34. // }
  35. }
  36. })
  37. };
  38. static But: FC<()> = |cx| {
  39. let mut count = use_state(cx, || 0);
  40. // let d = Dropper { name: "asd" };
  41. // let handler = move |_| {
  42. // dbg!(d.name);
  43. // };
  44. cx.render(rsx! {
  45. div {
  46. h1 { "Hifive counter: {count}" }
  47. {cx.children()}
  48. button { onclick: move |_| count += 1, "Up high!" }
  49. button { onclick: move |_| count -= 1, "Down low!" }
  50. // button { onclick: {handler}, "Down low!" }
  51. }
  52. })
  53. };
  54. // struct Dropper {
  55. // name: &'static str,
  56. // }
  57. // impl Drop for Dropper {
  58. // fn drop(&mut self) {
  59. // dbg!("dropped");
  60. // }
  61. // }