Skip to main content

ferroui_base/rendering/
z_index_comparer.rs

1use crate::{Ref, Visual};
2use std::cmp::Ordering;
3
4/// Orders visuals by their Z index.
5pub struct ZIndexComparer;
6
7impl ZIndexComparer {
8    /// Compares two visuals by Z index (the comparison is stable: use it
9    /// with a stable sort to keep collection order among equal indices).
10    pub fn compare(x: &Ref<Visual>, y: &Ref<Visual>) -> Ordering {
11        x.z_index().cmp(&y.z_index())
12    }
13
14    /// Compares two optional visuals; a missing visual has Z index zero.
15    pub fn compare_optional(x: Option<&Ref<Visual>>, y: Option<&Ref<Visual>>) -> Ordering {
16        x.map_or(0, |v| v.z_index()).cmp(&y.map_or(0, |v| v.z_index()))
17    }
18}