leptos_struct_table/
events.rsuse leptos::ev::MouseEvent;
use leptos::prelude::*;
use std::sync::Arc;
#[derive(Debug)]
pub struct ChangeEvent<Row: Send + Sync + 'static> {
pub row_index: usize,
pub changed_row: Signal<Row>,
}
impl<Row: Send + Sync + 'static> Clone for ChangeEvent<Row> {
fn clone(&self) -> Self {
*self
}
}
impl<Row: Send + Sync + 'static> Copy for ChangeEvent<Row> {}
#[derive(Debug)]
pub struct SelectionChangeEvent<Row: Send + Sync + 'static> {
pub selected: bool,
pub row_index: usize,
pub row: Signal<Row>,
}
impl<Row: Send + Sync + 'static> Clone for SelectionChangeEvent<Row> {
fn clone(&self) -> Self {
*self
}
}
impl<Row: Send + Sync + 'static> Copy for SelectionChangeEvent<Row> {}
#[derive(Debug)]
pub struct TableHeadEvent {
pub index: usize,
pub mouse_event: MouseEvent,
}
macro_rules! impl_default_arc_fn {
(
$(#[$meta:meta])*
$name:ident<$($ty:ident),*>($($arg_name:ident: $arg_ty:ty),*)
$(-> $ret_ty:ty)?
$({ default $default_return:expr })?
) => {
$(#[$meta])*
#[derive(Clone)]
pub struct $name<$($ty),*>(Arc<dyn Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync>);
impl<$($ty),*> Default for $name<$($ty),*> {
fn default() -> Self {
#[allow(unused_variables)]
Self(Arc::new(|$($arg_name: $arg_ty),*| {
$($default_return)?
}))
}
}
impl<F, $($ty),*> From<F> for $name<$($ty),*>
where F: Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync + 'static
{
fn from(f: F) -> Self { Self(Arc::new(f)) }
}
impl<$($ty),*> $name<$($ty),*> {
pub fn run(&self, $($arg_name: $arg_ty),*) $(-> $ret_ty)? {
(self.0)($($arg_name),*)
}
}
}
}
impl_default_arc_fn!(
EventHandler<T>(event: T)
);
pub(crate) use impl_default_arc_fn;