simple.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. use std::future::Future;
  2. use dioxus_core::{prelude::*, virtual_dom::Properties};
  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. #[derive(PartialEq)]
  13. struct Props {
  14. name: String,
  15. }
  16. impl Properties for Props {}
  17. fn root(ctx: &mut Context<Props>) -> VNode {
  18. // the regular html syntax
  19. // html! {
  20. // <html>
  21. // <Head />
  22. // <Body />
  23. // <Footer />
  24. // </html>
  25. // }
  26. // or a manually crated vnode
  27. {
  28. let mut node_0 = VNode::element("div");
  29. {
  30. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  31. // element_node.attrs.insert("blah", "blah");
  32. // element_node.children.extend(node_0.into_iter());
  33. }
  34. }
  35. let mut node_1: IterableNodes = ("Hello world!").into();
  36. node_1.first().insert_space_before_text();
  37. let mut node_2 = VNode::element("button");
  38. let node_3 = VNode::Component(VComponent::from_fn(
  39. Head,
  40. Props {
  41. name: "".to_string(),
  42. },
  43. ));
  44. {
  45. // let closure = Closure::wrap(Box::new(|_| {}) as Box<FnMut(_)>);
  46. // let closure_rc = std::rc::Rc::new(closure);
  47. // node_2
  48. // .as_velement_mut()
  49. // .expect("Not an element")
  50. // .events
  51. // .0
  52. // .insert("onclick".to_string(), closure_rc);
  53. }
  54. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  55. element_node.children.extend(node_1.into_iter());
  56. }
  57. if let Some(ref mut element_node) = node_0.as_velement_mut() {
  58. element_node.children.extend(node_2.into_iter());
  59. }
  60. node_0
  61. }
  62. }
  63. fn Head(ctx: &mut Context<Props>) -> VNode {
  64. html! {
  65. <head> "Head Section" </head>
  66. }
  67. }
  68. fn Body(ctx: &mut Context<Props>) -> VNode {
  69. html! {
  70. <body> {"Footer Section"}</body>
  71. }
  72. }
  73. fn Footer(ctx: &mut Context<Props>) -> VNode {
  74. let mut v = 10_i32;
  75. format!("Is this the real life, or is this fantasy, caught in a landslide");
  76. html! {
  77. <div>
  78. "Footer Section"
  79. "Footer Section"
  80. "Footer Section"
  81. "Footer Section"
  82. "Footer Section"
  83. "Footer Section"
  84. </div>
  85. }
  86. }