leptos_struct_table/
events.rs1use leptos::ev::MouseEvent;
2use leptos::prelude::*;
3use std::sync::Arc;
4
5#[derive(Debug)]
7pub struct ChangeEvent<Row: Send + Sync + 'static> {
8 pub row_index: usize,
10 pub changed_row: Signal<Row>,
12}
13
14impl<Row: Send + Sync + 'static> Clone for ChangeEvent<Row> {
15 fn clone(&self) -> Self {
16 *self
17 }
18}
19
20impl<Row: Send + Sync + 'static> Copy for ChangeEvent<Row> {}
21
22#[derive(Debug)]
24pub struct SelectionChangeEvent<Row: Send + Sync + 'static> {
25 pub selected: bool,
27 pub row_index: usize,
29 pub row: Signal<Row>,
31}
32
33impl<Row: Send + Sync + 'static> Clone for SelectionChangeEvent<Row> {
34 fn clone(&self) -> Self {
35 *self
36 }
37}
38
39impl<Row: Send + Sync + 'static> Copy for SelectionChangeEvent<Row> {}
40
41#[derive(Debug)]
43pub struct TableHeadEvent {
44 pub index: usize,
47 pub mouse_event: MouseEvent,
49}
50
51#[derive(Clone)]
54pub struct EventHandler<T>(Arc<dyn Fn(T) + Send + Sync>);
55
56impl<T> Default for EventHandler<T> {
57 fn default() -> Self {
58 #[allow(unused_variables)]
59 Self(Arc::new(|event: T| {}))
60 }
61}
62
63impl<F, T> From<F> for EventHandler<T>
64where
65 F: Fn(T) + Send + Sync + 'static,
66{
67 fn from(f: F) -> Self {
68 Self(Arc::new(f))
69 }
70}
71
72impl<T> EventHandler<T> {
73 #[inline]
74 pub fn run(&self, event: T) {
75 (self.0)(event)
76 }
77}