leptos_struct_table/
events.rs1use leptos::ev::MouseEvent;
2use std::rc::Rc;
3
4#[derive(Debug, Clone)]
6pub struct ChangeEvent<Row: Clone> {
7 pub row_index: usize,
9 pub col_index: usize,
11 pub changed_row: Row,
13}
14
15#[derive(Debug, Clone)]
17pub struct SelectionChangeEvent<Row: Clone> {
18 pub selected: bool,
20 pub row_index: usize,
22 pub row: Row,
24}
25
26#[derive(Debug)]
28pub struct TableHeadEvent {
29 pub index: usize,
32 pub mouse_event: MouseEvent,
34}
35
36macro_rules! impl_default_rc_fn {
37 (
38 $(#[$meta:meta])*
39 $name:ident<$($ty:ident),*>($($arg_name:ident: $arg_ty:ty),*)
40 $(-> $ret_ty:ty)?
41 $({ default $default_return:expr })?
42 ) => {
43 $(#[$meta])*
44 #[derive(Clone)]
45 pub struct $name<$($ty),*>(Rc<dyn Fn($($arg_ty),*) $(-> $ret_ty)?>);
46
47 impl<$($ty),*> Default for $name<$($ty),*> {
48 fn default() -> Self {
49 #[allow(unused_variables)]
50 Self(Rc::new(|$($arg_name: $arg_ty),*| {
51 $($default_return)?
52 }))
53 }
54 }
55
56 impl<F, $($ty),*> From<F> for $name<$($ty),*>
57 where F: Fn($($arg_ty),*) $(-> $ret_ty)? + 'static
58 {
59 fn from(f: F) -> Self { Self(Rc::new(f)) }
60 }
61
62 impl<$($ty),*> $name<$($ty),*> {
63 pub fn run(&self, $($arg_name: $arg_ty),*) $(-> $ret_ty)? {
64 (self.0)($($arg_name),*)
65 }
66 }
67 }
68}
69
70impl_default_rc_fn!(
71 EventHandler<T>(event: T)
74);
75
76pub(crate) use impl_default_rc_fn;