Try catalog theming approach with Button

This commit is contained in:
Héctor Ramón Jiménez 2024-03-23 19:23:08 +01:00
parent 2b00e8b145
commit 999ad2d288
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 89 additions and 55 deletions

33
core/src/closure.rs Normal file
View file

@ -0,0 +1,33 @@
//! Box closures with ease.
//!
//! These are just a bunch of types that wrap boxed closures with
//! blanket [`From`] implementations for easy conversions.
//!
//! Mainly, it allows functions to take `Into<T>` where `T` may end
//! up being a boxed closure.
/// A boxed closure that takes `A` by reference and produces `O`.
#[allow(missing_debug_implementations)]
pub struct Unary<'a, A, O>(pub Box<dyn Fn(&A) -> O + 'a>);
impl<'a, A, O, T> From<T> for Unary<'a, A, O>
where
T: Fn(&A) -> O + 'a,
{
fn from(f: T) -> Self {
Self(Box::new(f))
}
}
/// A boxed closure that takes `A` by reference and `B` by value and produces `O`.
#[allow(missing_debug_implementations)]
pub struct Binary<'a, A, B, O>(pub Box<dyn Fn(&A, B) -> O + 'a>);
impl<'a, A, B, O, T> From<T> for Binary<'a, A, B, O>
where
T: Fn(&A, B) -> O + 'a,
{
fn from(f: T) -> Self {
Self(Box::new(f))
}
}

View file

@ -19,6 +19,7 @@
pub mod alignment;
pub mod border;
pub mod clipboard;
pub mod closure;
pub mod event;
pub mod font;
pub mod gradient;