events.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. use core::panic;
  2. use dioxus_html::*;
  3. use crate::element::TuiElement;
  4. fn downcast(event: &PlatformEventData) -> plasmo::EventData {
  5. event
  6. .downcast::<plasmo::EventData>()
  7. .expect("event should be of type EventData")
  8. .clone()
  9. }
  10. pub(crate) struct SerializedHtmlEventConverter;
  11. impl HtmlEventConverter for SerializedHtmlEventConverter {
  12. fn convert_animation_data(&self, _: &PlatformEventData) -> AnimationData {
  13. panic!("animation events not supported")
  14. }
  15. fn convert_clipboard_data(&self, _: &PlatformEventData) -> ClipboardData {
  16. panic!("clipboard events not supported")
  17. }
  18. fn convert_composition_data(&self, _: &PlatformEventData) -> CompositionData {
  19. panic!("composition events not supported")
  20. }
  21. fn convert_drag_data(&self, _: &PlatformEventData) -> DragData {
  22. panic!("drag events not supported")
  23. }
  24. fn convert_focus_data(&self, event: &PlatformEventData) -> FocusData {
  25. if let plasmo::EventData::Focus(event) = downcast(event) {
  26. FocusData::new(event)
  27. } else {
  28. panic!("event should be of type Focus")
  29. }
  30. }
  31. fn convert_form_data(&self, event: &PlatformEventData) -> FormData {
  32. if let plasmo::EventData::Form(event) = downcast(event) {
  33. FormData::new(event)
  34. } else {
  35. panic!("event should be of type Form")
  36. }
  37. }
  38. fn convert_image_data(&self, _: &PlatformEventData) -> ImageData {
  39. panic!("image events not supported")
  40. }
  41. fn convert_keyboard_data(&self, event: &PlatformEventData) -> KeyboardData {
  42. if let plasmo::EventData::Keyboard(event) = downcast(event) {
  43. KeyboardData::new(event)
  44. } else {
  45. panic!("event should be of type Keyboard")
  46. }
  47. }
  48. fn convert_media_data(&self, _: &PlatformEventData) -> MediaData {
  49. panic!("media events not supported")
  50. }
  51. fn convert_mounted_data(&self, event: &PlatformEventData) -> MountedData {
  52. event.downcast::<TuiElement>().cloned().unwrap().into()
  53. }
  54. fn convert_mouse_data(&self, event: &PlatformEventData) -> MouseData {
  55. if let plasmo::EventData::Mouse(event) = downcast(event) {
  56. MouseData::new(event)
  57. } else {
  58. panic!("event should be of type Mouse")
  59. }
  60. }
  61. fn convert_pointer_data(&self, _: &PlatformEventData) -> PointerData {
  62. panic!("pointer events not supported")
  63. }
  64. fn convert_scroll_data(&self, _: &PlatformEventData) -> ScrollData {
  65. panic!("scroll events not supported")
  66. }
  67. fn convert_selection_data(&self, _: &PlatformEventData) -> SelectionData {
  68. panic!("selection events not supported")
  69. }
  70. fn convert_toggle_data(&self, _: &PlatformEventData) -> ToggleData {
  71. panic!("toggle events not supported")
  72. }
  73. fn convert_touch_data(&self, _: &PlatformEventData) -> TouchData {
  74. panic!("touch events not supported")
  75. }
  76. fn convert_transition_data(&self, _: &PlatformEventData) -> TransitionData {
  77. panic!("transition events not supported")
  78. }
  79. fn convert_wheel_data(&self, event: &PlatformEventData) -> WheelData {
  80. if let plasmo::EventData::Wheel(event) = downcast(event) {
  81. WheelData::new(event)
  82. } else {
  83. panic!("event should be of type Wheel")
  84. }
  85. }
  86. }