improve click callback builder

This commit is contained in:
hodasemi 2025-03-04 16:03:57 +01:00
parent 22994c97f6
commit d4997dff39

View file

@ -3,6 +3,7 @@ use std::any::Any;
use anyhow::Result; use anyhow::Result;
use super::ControllerButton; use super::ControllerButton;
use crate::prelude::*;
macro_rules! callbacks { macro_rules! callbacks {
($name:ident, $($cb:tt)*) => { ($name:ident, $($cb:tt)*) => {
@ -26,7 +27,7 @@ macro_rules! callbacks {
}; };
} }
callbacks!(ClickCallbacks, Fn() -> Result<()> + Send + Sync); callbacks!(ClickCallbacks, Fn(&mut GuiHandler) -> Result<()> + Send + Sync);
callbacks!(SelectCallbacks, Fn(bool) -> anyhow::Result<()> + Send + Sync); callbacks!(SelectCallbacks, Fn(bool) -> anyhow::Result<()> + Send + Sync);
callbacks!(CustomCallbacks, Fn(ControllerButton) -> anyhow::Result<bool> + Send + Sync); callbacks!(CustomCallbacks, Fn(ControllerButton) -> anyhow::Result<bool> + Send + Sync);
callbacks!(VecCallbacks, Fn(&dyn Any) -> Result<()> + Send + Sync); callbacks!(VecCallbacks, Fn(&dyn Any) -> Result<()> + Send + Sync);
@ -36,8 +37,8 @@ mod test {
use super::*; use super::*;
use anyhow::Result; use anyhow::Result;
fn normal_fn() -> impl Fn() -> Result<()> + Send + Sync { fn normal_fn() -> impl Fn(&mut GuiHandler) -> Result<()> + Send + Sync {
|| Ok(()) |_| Ok(())
} }
#[test] #[test]
@ -47,7 +48,10 @@ mod test {
impl Test { impl Test {
fn set_click_callbacks( fn set_click_callbacks(
&self, &self,
_callbacks: Vec<(&str, Box<dyn Fn() -> Result<()> + Send + Sync>)>, _callbacks: Vec<(
&str,
Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>,
)>,
) -> Result<()> { ) -> Result<()> {
Ok(()) Ok(())
} }