bevy_extended_ui 1.7.0

Create simply ui's with css and html for bevy.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
use crate::html::HtmlSource;
use bevy::prelude::*;
use once_cell::sync::Lazy;
use std::collections::{HashMap, VecDeque};
use std::sync::Mutex;

#[cfg(not(feature = "extended-framework"))]
use crate::widgets::{Body, UIGenID, WidgetId, WidgetKind};
#[cfg(not(feature = "extended-framework"))]
use std::collections::HashSet;

pub static UI_ID_GENERATE: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static BODY_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static DIV_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static FORM_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static BUTTON_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static CHECK_BOX_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static CHOICE_BOX_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static DIVIDER_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static FIELDSET_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static HEADLINE_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static HYPER_LINK_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static IMAGE_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static INPUT_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static DATE_PICKER_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static PARAGRAPH_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static TOOL_TIP_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static BADGE_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static PROGRESS_BAR_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static RADIO_BUTTON_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static SCROLL_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static SLIDER_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static COLOR_PICKER_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static SWITCH_BUTTON_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static TOGGLE_BUTTON_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));
pub static LIST_BOX_ID_POOL: Lazy<Mutex<IdPool>> = Lazy::new(|| Mutex::new(IdPool::new()));

/// A pool that manages reusable integer IDs for widgets.
/// It hands out new IDs or recycles freed IDs.
pub struct IdPool {
    /// The next ID to assign if no free ID exists.
    counter: usize,
    /// Queue of IDs that have been released and can be reused.
    free_list: VecDeque<usize>,
}

impl IdPool {
    /// Creates a new empty `IdPool`.
    pub fn new() -> Self {
        Self {
            counter: 0,
            free_list: VecDeque::new(),
        }
    }

    /// Acquires a new ID.
    /// Returns a recycled ID if available, otherwise generates a new one.
    pub fn acquire(&mut self) -> usize {
        if let Some(id) = self.free_list.pop_front() {
            id
        } else {
            let id = self.counter;
            self.counter += 1;
            id
        }
    }

    /// Releases an ID back to the pool for reuse.
    ///
    /// # Arguments
    ///
    /// * `id` - The ID to release.
    pub fn release(&mut self, id: usize) {
        self.free_list.push_back(id);
    }
}

/// Resource that registers and manages available UI HTML sources.
///
/// It stores named HTML sources and tracks the currently active UI.
#[derive(Default, Resource, Reflect, Debug)]
#[reflect(Resource)]
pub struct UiRegistry {
    /// Collection mapping UI names to their HTML source data.
    pub collection: HashMap<String, HtmlSource>,
    /// The currently active UI names.
    pub current: Option<Vec<String>>,

    pub ui_update: bool,
}

#[allow(deprecated)]
impl UiRegistry {
    /// Handles `ensure_legacy_registry_available` in the extended UI workflow.
    #[inline]
    fn ensure_legacy_registry_available() {
        #[cfg(feature = "extended-framework")]
        panic!(
            "UiRegistry is part of the legacy system and is disabled when `extended-framework` is active."
        );
    }

    /// Creates a new empty UI registry.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `new` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `new` with values from your app state and world context.
    /// ```
    pub fn new() -> Self {
        Self::ensure_legacy_registry_available();
        Self::default()
    }

    /// Adds a named UI HTML source to the registry.
    ///
    /// # Arguments
    ///
    /// * `name` - The name under which the UI source will be registered.
    /// * `source` - The HTML source data.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `add` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `add` with values from your app state and world context.
    /// ```
    pub fn add(&mut self, name: String, source: HtmlSource) {
        Self::ensure_legacy_registry_available();
        self.collection.insert(
            name.clone(),
            HtmlSource {
                source_id: name.clone(),
                ..source
            },
        );
    }

    /// Adds a UI source and marks it as currently in use.
    ///
    /// # Arguments
    ///
    /// * `name` - The name to register and use.
    /// * `source` - The HTML source data.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `add_and_use` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `add_and_use` with values from your app state and world context.
    /// ```
    pub fn add_and_use(&mut self, name: String, source: HtmlSource) {
        Self::ensure_legacy_registry_available();
        self.add(
            name.clone(),
            HtmlSource {
                source_id: name.clone(),
                ..source
            },
        );
        self.use_ui(&name);
    }

    /// Adds multiple UI sources and marks them as currently in use.
    ///
    /// # Arguments
    ///
    /// * `entries` - A list of UI names and HTML source data.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `add_and_use_multiple` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `add_and_use_multiple` with values from your app state and world context.
    /// ```
    pub fn add_and_use_multiple(&mut self, entries: Vec<(String, HtmlSource)>) {
        Self::ensure_legacy_registry_available();
        let mut names = Vec::with_capacity(entries.len());
        for (name, source) in entries {
            self.add(
                name.clone(),
                HtmlSource {
                    source_id: name.clone(),
                    ..source
                },
            );
            names.push(name);
        }
        self.use_uis(names);
    }

    /// Removes a UI source from the registry by its name.
    ///
    /// If the currently active UI list contains the given name,
    /// it will also be removed.
    ///
    /// # Arguments
    ///
    /// * `name` - The identifier of the UI to remove from the registry.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `remove` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `remove` with values from your app state and world context.
    /// ```
    pub fn remove(&mut self, name: &str) {
        Self::ensure_legacy_registry_available();
        if let Some(current) = &mut self.current {
            current.retain(|current| current != name);
            if current.is_empty() {
                self.current = None;
            }
        }
        self.collection.remove(name);
    }

    /// Removes a UI source and immediately switches to another one.
    ///
    /// This is useful when replacing a currently loaded UI with a new one.
    /// If the removed UI is currently active, it switches to `to_switch`.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the UI to be removed.
    /// * `to_switch` - The name of the UI to activate after removal.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `remove_and_use` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `remove_and_use` with values from your app state and world context.
    /// ```
    pub fn remove_and_use(&mut self, name: &str, to_switch: &str) {
        Self::ensure_legacy_registry_available();
        self.remove(name);
        self.use_ui(to_switch);
    }

    /// Removes all UI sources from the registry and clears the current UI list.
    ///
    /// This is typically used during global resets or cleanup operations.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `remove_all` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `remove_all` with values from your app state and world context.
    /// ```
    pub fn remove_all(&mut self) {
        Self::ensure_legacy_registry_available();
        self.collection.clear();
        self.current = None;
    }

    /// Retrieves a UI source by name.
    ///
    /// # Arguments
    ///
    /// * `name` - The UI name to look up.
    ///
    /// # Returns
    ///
    /// An optional reference to the `HtmlSource` if found.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `get` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `get` with values from your app state and world context.
    /// ```
    pub fn get(&self, name: &str) -> Option<&HtmlSource> {
        Self::ensure_legacy_registry_available();
        self.collection.get(name)
    }

    /// Retrieves a mutable UI source by name.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `get_mut` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `get_mut` with values from your app state and world context.
    /// ```
    pub fn get_mut(&mut self, name: &str) -> Option<&mut HtmlSource> {
        Self::ensure_legacy_registry_available();
        self.collection.get_mut(name)
    }

    /// Sets the currently active UI by name if it exists in the registry.
    ///
    /// If the UI with the given name exists in the internal collection, it will be marked
    /// as the currently active UI by setting the `current` field. If it does not exist,
    /// a warning will be logged and the current UI list will be cleared.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the UI to activate.
    ///
    /// # Behavior
    ///
    /// - If the named UI exists: `self.current` will be set to `Some(vec![name.to_string()])`.
    /// - If the named UI does not exist: `self.current` will be cleared, and a warning is logged.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `use_ui` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `use_ui` with values from your app state and world context.
    /// ```
    pub fn use_ui(&mut self, name: &str) {
        Self::ensure_legacy_registry_available();
        if self.get(name).is_some() {
            self.current = Some(vec![name.to_string()]);
            self.ui_update = true;
        } else {
            warn!("Ui was empty and will removed now!");
            self.current = None;
        }
    }

    /// Sets the currently active UIs by name if they exist in the registry.
    ///
    /// # Arguments
    ///
    /// * `names` - The UI names to activate.
    #[deprecated(
        note = "Legacy UiRegistry method. Prefer the extended-framework component entry via index.html."
    )]
    /// Handles `use_uis` in the extended UI workflow.
    ///
    /// # Examples
    ///
    /// ```rust
    /// // Call `use_uis` with values from your app state and world context.
    /// ```
    pub fn use_uis(&mut self, names: Vec<String>) {
        Self::ensure_legacy_registry_available();
        let mut valid = Vec::new();
        for name in names {
            if self.get(&name).is_some() {
                valid.push(name);
            } else {
                warn!("Ui was empty and will removed now!");
            }
        }

        if valid.is_empty() {
            self.current = None;
        } else {
            self.current = Some(valid);
        }
        self.ui_update = true;
    }
}

/// Resource flag used to control whether UI widgets should be initialized.
///
/// This resource wraps a single `bool` value indicating whether the widget initialization
/// logic should run during the next update cycle.
///
/// # Fields
/// - `0`: A `bool` flag. `true` means initialization should run; `false` means no initialization.
#[derive(Default, Resource, Debug)]
pub struct UiInitResource(pub bool);

/// Resource tracking the last UI usage name to detect changes.
#[cfg(not(feature = "extended-framework"))]
#[derive(Resource, Debug)]
struct LastUiUsage(pub Option<Vec<String>>);

/// Bevy plugin that manages the UI registry lifecycle and cleanup.
pub struct ExtendedRegistryPlugin;

impl Plugin for ExtendedRegistryPlugin {
    /// Initializes registry resources and hooks update systems.
    fn build(&self, app: &mut App) {
        #[cfg(feature = "extended-framework")]
        {
            let _ = app;
            panic!(
                "ExtendedRegistryPlugin is disabled when `extended-framework` is active. Use the component system with index.html instead."
            );
        }

        #[cfg(not(feature = "extended-framework"))]
        {
            app.init_resource::<UiInitResource>();
            app.init_resource::<UiRegistry>();
            app.add_systems(
                Update,
                (despawn_widget_ids, update_que)
                    .chain()
                    .run_if(resource_changed::<UiRegistry>),
            );
        }
    }
}

/// System that updates the UI entity queue.
/// Spawns UI entities if not present or reloads if a different UI is requested.
///
/// # Arguments
///
/// * `commands` - Commands for spawning/despawning entities.
/// * `ui_registry` - The UI registry resource.
/// * `query` - Query for entities with `HtmlSource`.
/// * `body_query` - Query for body entities without `HtmlSource` but with `HtmlBody`.
#[cfg(not(feature = "extended-framework"))]
fn update_que(
    mut commands: Commands,
    mut ui_registry: ResMut<UiRegistry>,
    mut ui_init: ResMut<UiInitResource>,
    mut structure_map: ResMut<crate::html::HtmlStructureMap>,
    query: Query<(Entity, &HtmlSource), With<HtmlSource>>,
    mut body_query: Query<(Entity, &mut Visibility, &Body), (Without<HtmlSource>, With<Body>)>,
) {
    structure_map.active = ui_registry.current.clone();

    let Some(active_names) = ui_registry.current.clone() else {
        for (entity, html_source) in query.iter() {
            hide_bound_bodies_for_source(&html_source.source_id, &mut body_query);

            commands.entity(entity).despawn();
        }
        ui_registry.ui_update = false;
        return;
    };
    let active_set: HashSet<String> = active_names.iter().cloned().collect();

    if ui_registry.ui_update {
        for (body_entity, _, body) in body_query.iter_mut() {
            if let Some(bind) = body.html_key.as_ref() {
                if active_set.contains(bind) {
                    commands.entity(body_entity).despawn();
                }
            }
        }

        for (entity, html_source) in query.iter() {
            if active_set.contains(&html_source.source_id) {
                commands.entity(entity).despawn();
            }
        }
    }

    let mut existing = HashSet::new();
    for (_, html_source) in query.iter() {
        if active_set.contains(&html_source.source_id) {
            existing.insert(html_source.source_id.clone());
        }
    }

    if ui_registry.ui_update {
        existing.clear();
    }

    for name in &active_names {
        if !existing.contains(name) {
            spawn_ui_source(&mut commands, name, &ui_registry, &mut ui_init);
        }
    }

    for (entity, html_source) in query.iter() {
        if !active_set.contains(&html_source.source_id) {
            hide_bound_bodies_for_source(&html_source.source_id, &mut body_query);
            commands.entity(entity).despawn();
        }
    }

    ui_registry.ui_update = false;
}

#[cfg(not(feature = "extended-framework"))]
fn hide_bound_bodies_for_source(
    source_id: &str,
    body_query: &mut Query<(Entity, &mut Visibility, &Body), (Without<HtmlSource>, With<Body>)>,
) {
    for (_, mut body_vis, body) in body_query.iter_mut() {
        if body.html_key.as_deref() == Some(source_id) {
            *body_vis = Visibility::Hidden;
        }
    }
}

/// Spawns a UI entity from a registered HTML source by name.
///
/// # Arguments
///
/// * `commands` - Commands to spawn the UI entity.
/// * `name` - The name of the UI to spawn.
/// * `ui_registry` - The UI registry resource.
#[cfg(not(feature = "extended-framework"))]
#[allow(deprecated)]
fn spawn_ui_source(
    commands: &mut Commands,
    name: &str,
    ui_registry: &UiRegistry,
    ui_init: &mut UiInitResource,
) {
    if let Some(source) = ui_registry.get(name) {
        ui_init.0 = true;
        commands.spawn((Name::new(name.to_string()), source.clone()));
        debug!("Loaded Registered UI {:?}", source);
    } else {
        warn!("UI source {} not found in registry", name);
    }
}

/// System that releases widget IDs back to their respective pools when widgets are despawned.
///
/// It avoids releasing IDs if the UI hasn't changed since the last run.
///
/// # Arguments
///
/// * `commands` - Commands to insert resources.
/// * `ui_registry` - Current UI registry resource.
/// * `last_ui_usage` - Optional resource tracking the last UI used.
/// * `query` - Query to iterate over entities with `WidgetId`.
/// * `widget_ids` - Query to access the `WidgetId` components.
#[cfg(not(feature = "extended-framework"))]
fn despawn_widget_ids(
    mut commands: Commands,
    ui_registry: Res<UiRegistry>,
    last_ui_usage: Option<Res<LastUiUsage>>,
    query: Query<Entity, With<WidgetId>>,
    widget_ids: Query<&WidgetId>,
    ui_id: Query<&UIGenID>,
) {
    if let Some(current) = ui_registry.current.as_ref() {
        if let Some(last_ui) = last_ui_usage {
            if last_ui.0.as_ref() == Some(current) {
                debug!("UI unchanged: current: {:?}", current);
            }
        }
    }

    for id in ui_id.iter() {
        UI_ID_GENERATE.lock().unwrap().release(id.get());
    }

    for entity in query.iter() {
        if let Ok(widget_id) = widget_ids.get(entity) {
            match widget_id.kind {
                WidgetKind::Body => BODY_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Div => DIV_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Form => FORM_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Headline => HEADLINE_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::HyperLink => HYPER_LINK_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Paragraph => PARAGRAPH_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::ToolTip => TOOL_TIP_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Badge => BADGE_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Button => BUTTON_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::CheckBox => CHECK_BOX_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Slider => SLIDER_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::ColorPicker => {
                    COLOR_PICKER_ID_POOL.lock().unwrap().release(widget_id.id)
                }
                WidgetKind::InputField => INPUT_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::DatePicker => DATE_PICKER_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::ChoiceBox => CHOICE_BOX_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Img => IMAGE_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::ProgressBar => {
                    PROGRESS_BAR_ID_POOL.lock().unwrap().release(widget_id.id)
                }
                WidgetKind::RadioButton => {
                    RADIO_BUTTON_ID_POOL.lock().unwrap().release(widget_id.id)
                }
                WidgetKind::SwitchButton => {
                    SWITCH_BUTTON_ID_POOL.lock().unwrap().release(widget_id.id)
                }
                WidgetKind::ToggleButton => {
                    TOGGLE_BUTTON_ID_POOL.lock().unwrap().release(widget_id.id)
                }
                WidgetKind::Scrollbar => SCROLL_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::Divider => DIVIDER_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::FieldSet => FIELDSET_ID_POOL.lock().unwrap().release(widget_id.id),
                WidgetKind::ListBox => LIST_BOX_ID_POOL.lock().unwrap().release(widget_id.id),
            }
        }
    }

    // Remember the current UI usage for the next run
    commands.insert_resource(LastUiUsage(ui_registry.current.clone()));
}