web_tick.rs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #![allow(non_upper_case_globals, non_snake_case)]
  2. //! Example: Webview Renderer
  3. //! -------------------------
  4. //!
  5. //! This example shows how to use the dioxus_desktop crate to build a basic desktop application.
  6. //!
  7. //! Under the hood, the dioxus_desktop crate bridges a native Dioxus VirtualDom with a custom prebuilt application running
  8. //! in the webview runtime. Custom handlers are provided for the webview instance to consume patches and emit user events
  9. //! into the native VDom instance.
  10. //!
  11. //! Currently, NodeRefs won't work properly, but all other event functionality will.
  12. use dioxus::prelude::*;
  13. fn main() {
  14. dioxus::desktop::launch(app);
  15. }
  16. fn app(cx: Scope) -> Element {
  17. let mut rng = SmallRng::from_entropy();
  18. cx.render(rsx! {
  19. table {
  20. tbody {
  21. (0..1_000).map(|f| {
  22. let label = Label::new(&mut rng);
  23. rsx! (Row { row_id: f, label: label })
  24. })
  25. }
  26. }
  27. })
  28. }
  29. #[derive(PartialEq, Props)]
  30. struct RowProps {
  31. row_id: usize,
  32. label: Label,
  33. }
  34. fn Row(cx: Scope<RowProps>) -> Element {
  35. let [adj, col, noun] = cx.props.label.0;
  36. cx.render(rsx! {
  37. tr {
  38. td { class:"col-md-1", "{cx.props.row_id}" }
  39. td { class:"col-md-1", onclick: move |_| { /* run onselect */ },
  40. a { class: "lbl", "{adj}" "{col}" "{noun}" }
  41. }
  42. td { class: "col-md-1",
  43. a { class: "remove", onclick: move |_| {/* remove */},
  44. span { class: "glyphicon glyphicon-remove remove", aria_hidden: "true" }
  45. }
  46. }
  47. td { class: "col-md-6" }
  48. }
  49. })
  50. }
  51. use rand::prelude::*;
  52. #[derive(PartialEq)]
  53. struct Label([&'static str; 3]);
  54. impl Label {
  55. fn new(rng: &mut SmallRng) -> Self {
  56. Label([
  57. ADJECTIVES.choose(rng).unwrap(),
  58. COLOURS.choose(rng).unwrap(),
  59. NOUNS.choose(rng).unwrap(),
  60. ])
  61. }
  62. }
  63. static ADJECTIVES: &[&str] = &[
  64. "pretty",
  65. "large",
  66. "big",
  67. "small",
  68. "tall",
  69. "short",
  70. "long",
  71. "handsome",
  72. "plain",
  73. "quaint",
  74. "clean",
  75. "elegant",
  76. "easy",
  77. "angry",
  78. "crazy",
  79. "helpful",
  80. "mushy",
  81. "odd",
  82. "unsightly",
  83. "adorable",
  84. "important",
  85. "inexpensive",
  86. "cheap",
  87. "expensive",
  88. "fancy",
  89. ];
  90. static COLOURS: &[&str] = &[
  91. "red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
  92. "orange",
  93. ];
  94. static NOUNS: &[&str] = &[
  95. "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
  96. "pizza", "mouse", "keyboard",
  97. ];
  98. #[cfg(target_arch = "wasm32")]
  99. fn intern_strings() {
  100. for adj in ADJECTIVES {
  101. wasm_bindgen::intern(adj);
  102. }
  103. for col in COLOURS {
  104. wasm_bindgen::intern(col);
  105. }
  106. for no in NOUNS {
  107. wasm_bindgen::intern(no);
  108. }
  109. wasm_bindgen::intern("col-md-1");
  110. wasm_bindgen::intern("col-md-6");
  111. wasm_bindgen::intern("glyphicon glyphicon-remove remove");
  112. wasm_bindgen::intern("remove");
  113. wasm_bindgen::intern("dioxus");
  114. wasm_bindgen::intern("lbl");
  115. wasm_bindgen::intern("true");
  116. }