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
51macro_rules! impl_default_arc_fn {
52 (
53 $(#[$meta:meta])*
54 $name:ident<$($ty:ident),*>($($arg_name:ident: $arg_ty:ty),*)
55 $(-> $ret_ty:ty)?
56 $({ default $default_return:expr })?
57 ) => {
58 $(#[$meta])*
59 #[derive(Clone)]
60 pub struct $name<$($ty),*>(Arc<dyn Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync>);
61
62 impl<$($ty),*> Default for $name<$($ty),*> {
63 fn default() -> Self {
64 #[allow(unused_variables)]
65 Self(Arc::new(|$($arg_name: $arg_ty),*| {
66 $($default_return)?
67 }))
68 }
69 }
70
71 impl<F, $($ty),*> From<F> for $name<$($ty),*>
72 where F: Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync + 'static
73 {
74 fn from(f: F) -> Self { Self(Arc::new(f)) }
75 }
76
77 impl<$($ty),*> $name<$($ty),*> {
78 pub fn run(&self, $($arg_name: $arg_ty),*) $(-> $ret_ty)? {
79 (self.0)($($arg_name),*)
80 }
81 }
82 }
83}
84
85impl_default_arc_fn!(
86 EventHandler<T>(event: T)
89);
90
91pub(crate) use impl_default_arc_fn;