simple.rs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. use std::future::Future;
  2. use dioxus_core::prelude::*;
  3. // use virtual_dom_rs::Closure;
  4. // Stop-gap while developing
  5. // Need to update the macro
  6. type VirtualNode = VNode;
  7. pub fn main() {
  8. let dom = VirtualDom::new_with_props(root);
  9. // let mut renderer = TextRenderer::new(dom);
  10. // let output = renderer.render();
  11. }
  12. struct Props {
  13. name: String,
  14. }
  15. fn root(ctx: &mut Context<Props>) -> VNode {
  16. // the regular html syntax
  17. // html! {
  18. // <html>
  19. // <Head />
  20. // <Body />
  21. // <Footer />
  22. // </html>
  23. // }
  24. // or a manually crated vnode
  25. {
  26. let mut node_0 = VNode::element("div");
  27. {
  28. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  29. // element_node.attrs.insert("blah", "blah");
  30. // element_node.children.extend(node_0.into_iter());
  31. }
  32. }
  33. let mut node_1: IterableNodes = ("Hello world!").into();
  34. node_1.first().insert_space_before_text();
  35. let mut node_2 = VNode::element("button");
  36. let node_3 = VNode::Component(VComponent {});
  37. {
  38. // let closure = Closure::wrap(Box::new(|_| {}) as Box<FnMut(_)>);
  39. // let closure_rc = std::rc::Rc::new(closure);
  40. // node_2
  41. // .as_velement_mut()
  42. // .expect("Not an element")
  43. // .events
  44. // .0
  45. // .insert("onclick".to_string(), closure_rc);
  46. }
  47. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  48. element_node.children.extend(node_1.into_iter());
  49. }
  50. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  51. element_node.children.extend(node_2.into_iter());
  52. }
  53. node_0
  54. }
  55. }
  56. fn Head(ctx: &mut Context<Props>) -> VNode {
  57. html! {
  58. <head>
  59. "Head Section"
  60. </head>
  61. }
  62. }
  63. fn Body(ctx: &mut Context<Props>) -> VNode {
  64. html! {
  65. <body>
  66. {"Footer Section"}
  67. </body>
  68. }
  69. }
  70. fn Footer(ctx: &mut Context<Props>) -> VNode {
  71. let mut v = 10_i32;
  72. format!("Is this the real life, or is this fantasy, caught in a landslide");
  73. html! {
  74. <div>
  75. "Footer Section"
  76. "Footer Section"
  77. "Footer Section"
  78. "Footer Section"
  79. "Footer Section"
  80. "Footer Section"
  81. </div>
  82. }
  83. }