use 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<Column> {
pub index: Column,
pub mouse_event: MouseEvent,
}
#[derive(Clone)]
pub struct EventHandler<T>(Arc<dyn Fn(T) + Send + Sync>);
impl<T> Default for EventHandler<T> {
fn default() -> Self {
#[allow(unused_variables)]
Self(Arc::new(|event: T| {}))
}
}
impl<F, T> From<F> for EventHandler<T>
where
F: Fn(T) + Send + Sync + 'static,
{
fn from(f: F) -> Self {
Self(Arc::new(f))
}
}
impl<T> EventHandler<T> {
#[inline]
pub fn run(&self, event: T) {
(self.0)(event)
}
}