dirty.rs
raw
//! Dirt classification for widget mutations.
//!
//! Every widget setter knows which pipeline stage its property affects and
//! marks the widget's dirt accordingly; the tree collects it through
//! [`Widget::take_dirt`](crate::widget::Widget::take_dirt) when a mutation
//! borrow ends. Layout dirt implies repainting; paint dirt does not imply
//! relayout.
/// What must be redone because of a mutation.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct Dirt {
/// The widget's size or content geometry may have changed.
pub layout: bool,
/// The widget's appearance changed within its current geometry.
pub paint: bool,
}
impl Dirt {
pub const CLEAN: Self = Self {
layout: false,
paint: false,
};
pub const PAINT: Self = Self {
layout: false,
paint: true,
};
/// Layout-affecting mutations always repaint too.
pub const LAYOUT: Self = Self {
layout: true,
paint: true,
};
pub fn is_clean(self) -> bool {
self == Self::CLEAN
}
#[must_use]
pub fn union(self, other: Self) -> Self {
Self {
layout: self.layout || other.layout,
paint: self.paint || other.paint,
}
}
/// Mark a layout-affecting change.
pub fn mark_layout(&mut self) {
*self = self.union(Self::LAYOUT);
}
/// Mark a paint-only change.
pub fn mark_paint(&mut self) {
*self = self.union(Self::PAINT);
}
}