#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Invalidation(pub u16);
impl Invalidation {
pub const NONE: Self = Self(0);
pub const LAYOUT: Self = Self(1 << 0);
pub const RESHAPE: Self = Self(1 << 1);
pub const PAINT: Self = Self(1 << 2);
pub const COMPOSITE: Self = Self(1 << 3);
pub const PROMOTION: Self = Self(1 << 4);
pub const STACKING: Self = Self(1 << 5);
pub const HIT_TEST: Self = Self(1 << 6);
pub const TRANSITION: Self = Self(1 << 7);
pub const ASSET: Self = Self(1 << 8);
pub const INHERIT: Self = Self(1 << 9);
pub const ALL: Self = Self(u16::MAX);
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
pub const fn intersects(self, other: Self) -> bool {
self.0 & other.0 != 0
}
pub const fn is_empty(self) -> bool {
self.0 == 0
}
}
#[derive(Debug, Clone, Copy)]
pub struct NodeCtx<'a> {
pub promoted: bool,
pub kind: &'a str,
}
pub enum Invalidate<T: 'static> {
Fixed(Invalidation),
Computed(fn(Option<&T>, Option<&T>, &NodeCtx<'_>) -> Invalidation),
}
impl<T> Invalidate<T> {
pub fn eval(&self, old: Option<&T>, new: Option<&T>, node: &NodeCtx<'_>) -> Invalidation {
match self {
Invalidate::Fixed(inv) => *inv,
Invalidate::Computed(f) => f(old, new, node),
}
}
}