Skip to main content

densa_ui/
id.rs

1/// Identifies a widget in a [`Ui`](crate::Ui).
2///
3/// An id stays valid until its widget is removed. A removed widget's slot can hold another
4/// widget later, under another generation, so an old id never reaches the new widget.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
6pub struct WidgetId {
7    pub(crate) index: u32,
8    pub(crate) generation: u32,
9}
10
11impl WidgetId {
12    pub(crate) fn slot(self) -> usize {
13        self.index as usize
14    }
15}