#[macro_export]
macro_rules! impl_widget_callback {
(
$callback_wrapper:ident,
$option_callback_wrapper:ident,
$callback_value:ident,
$callback_ty:ident
) => {
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[repr(C)]
pub struct $callback_wrapper {
pub refany: RefAny,
pub callback: $callback_value,
}
#[repr(C)]
pub struct $callback_value {
pub cb: $callback_ty,
pub ctx: azul_core::refany::OptionRefAny,
}
azul_css::impl_option!(
$callback_wrapper,
$option_callback_wrapper,
copy = false,
[Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash]
);
impl $callback_value {
pub fn create<I: Into<$callback_value>>(cb: I) -> $callback_value {
cb.into()
}
}
impl ::core::fmt::Display for $callback_value {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl ::core::fmt::Debug for $callback_value {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let callback = stringify!($callback_value);
write!(f, "{} @ 0x{:x}", callback, self.cb as usize)
}
}
impl Clone for $callback_value {
fn clone(&self) -> Self {
$callback_value {
cb: self.cb.clone(),
ctx: self.ctx.clone(),
}
}
}
impl core::hash::Hash for $callback_value {
fn hash<H>(&self, state: &mut H)
where
H: ::core::hash::Hasher,
{
state.write_usize(self.cb as usize);
}
}
impl PartialEq for $callback_value {
fn eq(&self, rhs: &Self) -> bool {
self.cb as usize == rhs.cb as usize
}
}
impl PartialOrd for $callback_value {
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
Some((self.cb as usize).cmp(&(other.cb as usize)))
}
}
impl Ord for $callback_value {
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
(self.cb as usize).cmp(&(other.cb as usize))
}
}
impl Eq for $callback_value {}
impl From<$callback_ty> for $callback_value {
fn from(cb: $callback_ty) -> $callback_value {
$callback_value {
cb,
ctx: azul_core::refany::OptionRefAny::None,
}
}
}
impl From<crate::callbacks::Callback> for $callback_value {
fn from(cb: crate::callbacks::Callback) -> $callback_value {
$callback_value {
cb: unsafe { core::mem::transmute(cb.cb) },
ctx: cb.ctx,
}
}
}
};
}
pub mod button;
pub mod check_box;
pub mod color_input;
pub mod file_input;
pub mod label;
pub mod drop_down;
pub mod frame;
pub mod list_view;
pub mod node_graph;
pub mod number_input;
pub mod progressbar;
pub mod ribbon;
pub mod tabs;
pub mod text_input;
pub mod titlebar;
pub mod tree_view;