components.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. use dioxus::prelude::*;
  2. fn main() {
  3. rink::launch(app);
  4. }
  5. #[derive(Props, PartialEq)]
  6. struct QuadrentProps {
  7. color: String,
  8. text: String,
  9. }
  10. fn Quadrent(cx: Scope<QuadrentProps>) -> Element {
  11. cx.render(rsx! {
  12. div {
  13. border_width: "1px",
  14. width: "50%",
  15. height: "100%",
  16. background_color: "{cx.props.color}",
  17. justify_content: "center",
  18. align_items: "center",
  19. "{cx.props.text}"
  20. }
  21. })
  22. }
  23. fn app(cx: Scope) -> Element {
  24. cx.render(rsx! {
  25. div {
  26. width: "100%",
  27. height: "100%",
  28. flex_direction: "column",
  29. div {
  30. width: "100%",
  31. height: "50%",
  32. flex_direction: "row",
  33. Quadrent{
  34. color: "red".to_string(),
  35. text: "[A]".to_string()
  36. },
  37. Quadrent{
  38. color: "black".to_string(),
  39. text: "[B]".to_string()
  40. }
  41. }
  42. div {
  43. width: "100%",
  44. height: "50%",
  45. flex_direction: "row",
  46. Quadrent{
  47. color: "green".to_string(),
  48. text: "[C]".to_string()
  49. },
  50. Quadrent{
  51. color: "blue".to_string(),
  52. text: "[D]".to_string()
  53. }
  54. }
  55. }
  56. })
  57. }