spread.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md.
  4. use dioxus::{
  5. core::{exports::bumpalo::Bump, Attribute, HasAttributesBox},
  6. html::{ExtendedGlobalAttributesMarker, GlobalAttributesExtension},
  7. prelude::*,
  8. };
  9. fn main() {
  10. dioxus_desktop::launch(app);
  11. }
  12. fn app(cx: Scope) -> Element {
  13. cx.render(::dioxus::core::LazyNodes::new(
  14. move |__cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
  15. static TEMPLATE: ::dioxus::core::Template = ::dioxus::core::Template {
  16. name: "src/main.rs:15:15:289",
  17. roots: &[::dioxus::core::TemplateNode::Dynamic { id: 0usize }],
  18. node_paths: &[&[0u8]],
  19. attr_paths: &[],
  20. };
  21. ::dioxus::core::VNode {
  22. parent: None,
  23. key: None,
  24. template: std::cell::Cell::new(TEMPLATE),
  25. root_ids: dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(
  26. 1usize,
  27. __cx.bump(),
  28. )
  29. .into(),
  30. dynamic_nodes: __cx.bump().alloc([__cx.component(
  31. Component,
  32. Props {
  33. bump: __cx.bump(),
  34. attributes: Vec::new(),
  35. }
  36. .width("hello"),
  37. "Component",
  38. )]),
  39. dynamic_attrs: __cx.bump().alloc([]),
  40. }
  41. },
  42. ))
  43. }
  44. #[derive(Props)]
  45. struct Props<'a> {
  46. bump: &'a Bump,
  47. attributes: Vec<Attribute<'a>>,
  48. }
  49. impl<'a> HasAttributesBox<'a, Props<'a>> for Props<'a> {
  50. fn push_attribute(
  51. mut self,
  52. name: &'a str,
  53. ns: Option<&'static str>,
  54. attr: impl IntoAttributeValue<'a>,
  55. volatile: bool,
  56. ) -> Self {
  57. self.attributes.push(Attribute {
  58. name,
  59. namespace: ns,
  60. value: attr.into_value(self.bump),
  61. volatile,
  62. });
  63. self
  64. }
  65. }
  66. impl ExtendedGlobalAttributesMarker for Props<'_> {}
  67. fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
  68. todo!()
  69. }