Skip to main content

ferroui_base/controls/
resources_changed_event_args.rs

1use std::cell::Cell;
2
3/// Describes a change to the resources visible to a resource host.
4///
5/// Each notification carries a new sequence number, which lets a host that is
6/// reached through more than one path ignore a notification it has already
7/// handled.
8#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
9pub struct ResourcesChangedEventArgs {
10    pub sequence_number: i32,
11}
12
13crate::ferro_thread_local! {
14    static LAST_SEQUENCE_NUMBER: Cell<i32> = const { Cell::new(0) };
15}
16
17impl ResourcesChangedEventArgs {
18    pub fn new(sequence_number: i32) -> Self {
19        Self { sequence_number }
20    }
21
22    /// Creates event arguments with the next sequence number.
23    pub fn create() -> Self {
24        let next = LAST_SEQUENCE_NUMBER.get().wrapping_add(1);
25        LAST_SEQUENCE_NUMBER.set(next);
26        Self { sequence_number: next }
27    }
28}