voxel-framework 0.13.0

A reusable voxel engine framework built on 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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//! Optional hotbar presentation and inventory content.

use crate::items::HotbarState;
use bevy::prelude::*;

mod content;
pub use content::{HotbarContentPlugin, HotbarPickupPulse, ItemIconPalette};

// ─── Hotbar UI ────────────────────────────────────────────────────────────────
//
// Gated on the `items` feature: presentation reads the shared HotbarState.

/// Visual configuration for the [`HotbarUiPlugin`] slot row.
///
/// Insert this resource before adding [`HotbarUiPlugin`] to customize the
/// hotbar. Visibility and slot count are consumed on `Startup`; rebuilding the
/// slot count at runtime is unsupported. Colors and sizing are read each frame.
///
/// # Default values
///
/// | Field            | Default                             |
/// |------------------|-------------------------------------|
/// | `visible`        | `true`                              |
/// | `slot_size`      | `50.0` px                           |
/// | `slot_gap`       | `4.0` px                            |
/// | `slot_color`     | `[0.15, 0.15, 0.15, 0.85]` (dark)  |
/// | `selected_color` | `[0.45, 0.45, 0.45, 0.95]` (light) |
#[derive(Resource, Debug, Clone)]
pub struct HotbarUiConfig {
    /// When `false`, the hotbar is not spawned. Use this to disable the hotbar
    /// entirely without removing [`HotbarUiPlugin`] from the app.
    pub visible: bool,
    /// Preferred square slot size in logical pixels; shrinks to fit the row.
    /// Content mode caps this at 50px; legacy mode preserves larger sizes.
    pub slot_size: f32,
    /// Horizontal gap between adjacent slot nodes in logical pixels.
    pub slot_gap: f32,
    /// RGBA background color applied to unselected hotbar slots in sRGB.
    pub slot_color: [f32; 4],
    /// RGBA background color applied to the currently selected slot in sRGB. Updated from [`HotbarState`] every frame.
    pub selected_color: [f32; 4],
}

impl Default for HotbarUiConfig {
    fn default() -> Self {
        Self {
            visible: true,
            slot_size: 50.0,
            slot_gap: 4.0,
            slot_color: [0.15, 0.15, 0.15, 0.85],
            selected_color: [0.45, 0.45, 0.45, 0.95],
        }
    }
}

/// Border and empty-slot styling for the [`HotbarUiPlugin`] slot row.
///
/// [`HotbarUiPlugin`] initializes this resource with defaults that reproduce
/// the look the hotbar always had; insert your own value (before or after the
/// plugin) to change it. The style is read every frame, so it can be changed at
/// runtime. It lives next to [`HotbarUiConfig`] instead of inside it so that
/// existing `HotbarUiConfig { .. }` literals keep compiling.
///
/// Widths are logical pixels. A width that is negative or not finite draws no
/// border, and a border never grows past half of the fitted slot size. Colors
/// are sRGB RGBA, like the fill colors in [`HotbarUiConfig`].
///
/// `empty_slot_alpha` multiplies the alpha of the fill and of the border of
/// slots known to be empty. Only [`HotbarContentPlugin`] knows what a slot
/// holds, so without it no slot is faded. The selected slot is never faded, so
/// the selection stays visible on an empty slot. Values are clamped to
/// `0.0..=1.0`; a value that is not finite fades nothing.
///
/// # Default values
///
/// | Field                   | Default                |
/// |-------------------------|------------------------|
/// | `border_width`          | `2.0` px               |
/// | `border_color`          | `[0.6, 0.6, 0.6, 0.6]` |
/// | `selected_border_width` | `2.0` px               |
/// | `selected_border_color` | `[0.6, 0.6, 0.6, 0.6]` |
/// | `empty_slot_alpha`      | `1.0` (no fading)      |
///
/// # Example
///
/// ```rust,no_run
/// use bevy::prelude::*;
/// use voxel_framework::prelude::*;
///
/// App::new()
///     .add_plugins(DefaultPlugins)
///     .insert_resource(HotbarState::new(9))
///     .insert_resource(HotbarSlotStyle {
///         border_width: 1.0,
///         selected_border_width: 3.0,
///         selected_border_color: [1.0, 1.0, 1.0, 1.0],
///         empty_slot_alpha: 0.2,
///         ..Default::default()
///     })
///     .insert_resource(HotbarPickupPulse {
///         scale: 1.15,
///         duration: 0.2,
///     })
///     .add_plugins((
///         HotbarPlugin,
///         HotbarUiPlugin,
///         HotbarContentPlugin::<DefaultItem>::new(),
///     ));
/// ```
#[derive(Resource, Debug, Clone, PartialEq)]
pub struct HotbarSlotStyle {
    /// Border width of unselected slots in logical pixels.
    pub border_width: f32,
    /// sRGB RGBA border color of unselected slots.
    pub border_color: [f32; 4],
    /// Border width of the selected slot in logical pixels.
    pub selected_border_width: f32,
    /// sRGB RGBA border color of the selected slot.
    pub selected_border_color: [f32; 4],
    /// Alpha multiplier for the fill and border of empty, unselected slots.
    pub empty_slot_alpha: f32,
}

impl Default for HotbarSlotStyle {
    fn default() -> Self {
        Self {
            border_width: 2.0,
            border_color: [0.6, 0.6, 0.6, 0.6],
            selected_border_width: 2.0,
            selected_border_color: [0.6, 0.6, 0.6, 0.6],
            empty_slot_alpha: 1.0,
        }
    }
}

impl HotbarSlotStyle {
    // Border width that is safe to hand to the layout: never negative or NaN.
    fn width(&self, selected: bool) -> f32 {
        let width = if selected {
            self.selected_border_width
        } else {
            self.border_width
        };
        if width.is_finite() {
            width.max(0.0)
        } else {
            0.0
        }
    }

    // Alpha multiplier for a slot: 1.0 unless it is an empty, unselected slot.
    fn fade(&self, selected: bool, empty: bool) -> f32 {
        if selected || !empty || !self.empty_slot_alpha.is_finite() {
            1.0
        } else {
            self.empty_slot_alpha.clamp(0.0, 1.0)
        }
    }

    fn border_color(&self, selected: bool, empty: bool) -> Color {
        let [r, g, b, a] = if selected {
            self.selected_border_color
        } else {
            self.border_color
        };
        Color::srgba(r, g, b, a * self.fade(selected, empty))
    }
}

/// Marker for the hotbar root container.
#[derive(Component)]
struct HotbarUiRoot;

#[derive(Component)]
struct HotbarUiRow;

/// Marker for individual hotbar slot nodes. Holds the slot index.
#[derive(Component)]
struct HotbarSlot(usize);

/// Whether a slot's inventory entry is empty. Added and kept up to date by the
/// content extension; a slot without it is not known to be empty.
#[derive(Component)]
struct SlotContent {
    empty: bool,
}

fn spawn_hotbar_ui(
    mut commands: Commands,
    config: Res<HotbarUiConfig>,
    hotbar: Res<HotbarState>,
    content: Option<Res<content::ContentEnabled>>,
    style: Option<Res<HotbarSlotStyle>>,
) {
    if !config.visible {
        return;
    }
    let style = style.as_deref().cloned().unwrap_or_default();
    let size = if content.is_some() {
        config.slot_size.clamp(0.0, 50.0)
    } else {
        config.slot_size.max(0.0)
    };
    commands
        .spawn((
            HotbarUiRoot,
            Node {
                width: percent(100),
                position_type: PositionType::Absolute,
                bottom: px(16),
                padding: UiRect::horizontal(px(16)),
                flex_direction: FlexDirection::Column,
                align_items: AlignItems::Center,
                ..default()
            },
        ))
        .with_children(|root| {
            root.spawn((
                HotbarUiRow,
                Node {
                    width: percent(100),
                    flex_direction: FlexDirection::Row,
                    justify_content: JustifyContent::Center,
                    align_items: AlignItems::Center,
                    column_gap: px(config.slot_gap.max(0.0)),
                    ..default()
                },
            ))
            .with_children(|row| {
                for i in 0..hotbar.slots {
                    let selected = i == hotbar.selected;
                    row.spawn((
                        HotbarSlot(i),
                        Node {
                            width: px(size),
                            min_width: px(0),
                            aspect_ratio: Some(1.0),
                            flex_shrink: 1.0,
                            border: UiRect::all(px(style.width(selected))),
                            justify_content: JustifyContent::Center,
                            align_items: AlignItems::Center,
                            ..default()
                        },
                        BackgroundColor(slot_color(&config, selected, 1.0)),
                        BorderColor::all(style.border_color(selected, false)),
                    ));
                }
            });
        });
}

// Flex shrinking alone does not recompute the aspect-ratio-derived height.
fn fit_hotbar(
    windows: Query<&Window, With<bevy::window::PrimaryWindow>>,
    scale: Option<Res<bevy::ui::UiScale>>,
    config: Res<HotbarUiConfig>,
    content: Option<Res<content::ContentEnabled>>,
    mut slots: Query<&mut Node, With<HotbarSlot>>,
    mut rows: Query<&mut Node, (With<HotbarUiRow>, Without<HotbarSlot>)>,
) {
    let Ok(window) = windows.single() else {
        return;
    };
    let scale = scale.map_or(1.0, |scale| scale.0).max(f32::EPSILON);
    let available = (window.width() / scale - 32.0).max(0.0);
    let count = slots.iter().count();
    let gaps = count.saturating_sub(1) as f32;
    let gap = config.slot_gap.max(0.0).min(available / gaps.max(1.0));
    let preferred = if content.is_some() {
        config.slot_size.clamp(0.0, 50.0)
    } else {
        config.slot_size.max(0.0)
    };
    let size = ((available - gap * gaps) / count.max(1) as f32).clamp(0.0, preferred);
    for mut node in &mut slots {
        if node.width != px(size) || node.height != px(size) {
            node.width = px(size);
            node.height = px(size);
            node.flex_shrink = 0.0;
        }
    }
    for mut row in &mut rows {
        if row.column_gap != px(gap) {
            row.column_gap = px(gap);
        }
    }
}

fn slot_color(config: &HotbarUiConfig, selected: bool, fade: f32) -> Color {
    let [r, g, b, a] = if selected {
        config.selected_color
    } else {
        config.slot_color
    };
    Color::srgba(r, g, b, a * fade)
}

// Applies selection, border style and empty-slot fading. Runs after
// `fit_hotbar` (borders are limited to half of the fitted size) and after the
// content extension has published which slots are empty.
fn update_hotbar_selection(
    hotbar: Res<HotbarState>,
    config: Res<HotbarUiConfig>,
    style: Option<Res<HotbarSlotStyle>>,
    mut slots: Query<(
        &HotbarSlot,
        &mut Node,
        &mut BackgroundColor,
        &mut BorderColor,
        Option<&SlotContent>,
    )>,
) {
    let style = style.as_deref().cloned().unwrap_or_default();
    for (slot, mut node, mut bg, mut border_color, content) in &mut slots {
        let selected = slot.0 == hotbar.selected;
        let empty = content.is_some_and(|content| content.empty);
        let color = slot_color(&config, selected, style.fade(selected, empty));
        if bg.0 != color {
            bg.0 = color;
        }
        let color = BorderColor::all(style.border_color(selected, empty));
        if *border_color != color {
            *border_color = color;
        }
        // Until `fit_hotbar` has sized the slot there is no size to limit by.
        let limit = match (node.width, node.height) {
            (Val::Px(width), Val::Px(_)) => width / 2.0,
            _ => f32::INFINITY,
        };
        let border = UiRect::all(px(style.width(selected).min(limit)));
        if node.border != border {
            node.border = border;
        }
    }
}

/// Plugin that renders a horizontal hotbar at the bottom center of the screen.
///
/// Reads [`HotbarState`] on startup to determine the number of slots, spawns
/// one [`Node`] quad per slot, and reads selection in PostUpdate before UI layout.
/// It works without an inventory. Add [`HotbarContentPlugin<I>`] for item content.
///
/// Customize via [`HotbarUiConfig`] inserted before this plugin. Borders and
/// the alpha of empty slots come from [`HotbarSlotStyle`]; the optional pickup
/// reaction is [`HotbarPickupPulse`].
///
/// # Example
///
/// ```rust,no_run
/// use bevy::prelude::*;
/// use voxel_framework::ui::{HotbarUiPlugin, HotbarUiConfig};
///
/// App::new()
///     .insert_resource(HotbarUiConfig {
///         slot_size: 64.0,
///         slot_gap: 6.0,
///         ..Default::default()
///     })
///     .add_plugins(HotbarUiPlugin);
/// ```
pub struct HotbarUiPlugin;

impl Plugin for HotbarUiPlugin {
    fn build(&self, app: &mut App) {
        app.init_resource::<HotbarUiConfig>();
        app.init_resource::<HotbarSlotStyle>();
        app.add_systems(Startup, spawn_hotbar_ui);
        app.add_systems(
            PostUpdate,
            (fit_hotbar, update_hotbar_selection)
                .chain()
                .before(bevy::ui::UiSystems::Prepare),
        );
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn fourteen_slots_reserve_horizontal_screen_margin() {
        let mut app = App::new();
        app.insert_resource(HotbarState::new(14))
            .add_plugins(HotbarUiPlugin);
        app.update();
        let world = app.world_mut();
        let root = world
            .query_filtered::<&Node, With<HotbarUiRoot>>()
            .single(world)
            .unwrap();
        assert_eq!(root.padding.left, Val::Px(16.0));
        assert_eq!(root.padding.right, Val::Px(16.0));
        assert_eq!(world.query::<&HotbarSlot>().iter(world).count(), 14);
    }
    #[test]
    fn legacy_ui_needs_no_inventory_or_content_plugin() {
        let mut app = App::new();
        app.insert_resource(HotbarState::new(9))
            .add_plugins(HotbarUiPlugin);
        app.update();
        app.world_mut().resource_mut::<HotbarState>().select(8);
        app.update();
        let config = app.world().resource::<HotbarUiConfig>().clone();
        let world = app.world_mut();
        assert_eq!(world.query::<&HotbarSlot>().iter(world).count(), 9);
        for (slot, bg) in world.query::<(&HotbarSlot, &BackgroundColor)>().iter(world) {
            assert_eq!(bg.0, slot_color(&config, slot.0 == 8, 1.0));
        }
        assert_eq!(world.query::<&Text>().iter(world).count(), 0);
    }
    #[test]
    fn fourteen_slots_resize_both_dimensions_and_respect_ui_scale() {
        let mut app = App::new();
        app.insert_resource(HotbarState::new(14))
            .insert_resource(bevy::ui::UiScale(1.0))
            .add_plugins(HotbarUiPlugin);
        let window = app
            .world_mut()
            .spawn((
                Window {
                    resolution: (600, 600).into(),
                    ..default()
                },
                bevy::window::PrimaryWindow,
            ))
            .id();
        for (width, scale) in [(600, 1.0), (800, 1.0), (1280, 1.0), (1920, 1.0), (800, 2.0)] {
            app.world_mut()
                .get_mut::<Window>(window)
                .unwrap()
                .resolution
                .set(width as f32, 600.0);
            app.world_mut().resource_mut::<bevy::ui::UiScale>().0 = scale;
            app.update();
            let expected = ((width as f32 / scale - 32.0 - 13.0 * 4.0) / 14.0).min(50.0);
            let world = app.world_mut();
            for node in world
                .query_filtered::<&Node, With<HotbarSlot>>()
                .iter(world)
            {
                assert_eq!(node.width, px(expected));
                assert_eq!(node.height, px(expected));
            }
        }
    }

    const BORDER: [f32; 4] = [0.1, 0.2, 0.3, 0.4];
    const SELECTED_BORDER: [f32; 4] = [0.9, 0.8, 0.7, 1.0];

    fn styled_app(style: HotbarSlotStyle) -> App {
        let mut app = App::new();
        app.insert_resource(HotbarState::new(3))
            .insert_resource(style)
            .add_plugins(HotbarUiPlugin);
        app
    }

    // (border, border color, fill) of every slot, by slot index.
    fn slots(app: &mut App) -> Vec<(UiRect, BorderColor, Color)> {
        let world = app.world_mut();
        let mut slots: Vec<_> = world
            .query::<(&HotbarSlot, &Node, &BorderColor, &BackgroundColor)>()
            .iter(world)
            .map(|(slot, node, border, bg)| (slot.0, node.border, *border, bg.0))
            .collect();
        slots.sort_by_key(|slot| slot.0);
        slots
            .into_iter()
            .map(|(_, border, color, bg)| (border, color, bg))
            .collect()
    }

    fn color([r, g, b, a]: [f32; 4]) -> BorderColor {
        BorderColor::all(Color::srgba(r, g, b, a))
    }

    #[test]
    fn default_style_keeps_the_historical_borders_and_fills() {
        assert_eq!(
            HotbarSlotStyle::default(),
            HotbarSlotStyle {
                border_width: 2.0,
                border_color: [0.6, 0.6, 0.6, 0.6],
                selected_border_width: 2.0,
                selected_border_color: [0.6, 0.6, 0.6, 0.6],
                empty_slot_alpha: 1.0,
            }
        );
        let mut app = App::new();
        app.insert_resource(HotbarState::new(3))
            .add_plugins(HotbarUiPlugin);
        assert_eq!(
            *app.world().resource::<HotbarSlotStyle>(),
            HotbarSlotStyle::default()
        );
        for _ in 0..2 {
            app.update();
            let slots = slots(&mut app);
            assert_eq!(slots.len(), 3);
            for (index, (border, border_color, bg)) in slots.into_iter().enumerate() {
                assert_eq!(border, UiRect::all(Val::Px(2.0)));
                assert_eq!(
                    border_color,
                    BorderColor::all(Color::srgba(0.6, 0.6, 0.6, 0.6))
                );
                let expected = if index == 0 {
                    Color::srgba(0.45, 0.45, 0.45, 0.95)
                } else {
                    Color::srgba(0.15, 0.15, 0.15, 0.85)
                };
                assert_eq!(bg, expected);
            }
        }
    }

    #[test]
    fn configured_borders_distinguish_the_selected_slot_and_follow_it() {
        let mut app = styled_app(HotbarSlotStyle {
            border_width: 1.0,
            border_color: BORDER,
            selected_border_width: 4.0,
            selected_border_color: SELECTED_BORDER,
            ..default()
        });
        let normal = (UiRect::all(Val::Px(1.0)), color(BORDER));
        let selected = (UiRect::all(Val::Px(4.0)), color(SELECTED_BORDER));
        let borders = |app: &mut App| -> Vec<(UiRect, BorderColor)> {
            slots(app)
                .into_iter()
                .map(|(border, color, _)| (border, color))
                .collect()
        };
        app.update();
        assert_eq!(borders(&mut app), vec![selected, normal, normal]);
        app.world_mut().resource_mut::<HotbarState>().select(2);
        app.update();
        assert_eq!(borders(&mut app), vec![normal, normal, selected]);
        // The style is read every frame.
        app.world_mut()
            .resource_mut::<HotbarSlotStyle>()
            .border_width = 3.0;
        app.update();
        assert_eq!(borders(&mut app)[0].0, UiRect::all(Val::Px(3.0)));
        assert_eq!(borders(&mut app)[2], selected);
    }

    #[test]
    fn negative_or_non_finite_border_widths_draw_no_border() {
        for width in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, -3.0] {
            let mut app = styled_app(HotbarSlotStyle {
                border_width: width,
                selected_border_width: width,
                ..default()
            });
            // Checked at spawn and again after a styling pass.
            for _ in 0..2 {
                app.update();
                for (border, _, _) in slots(&mut app) {
                    assert_eq!(border, UiRect::all(Val::Px(0.0)), "width {width}");
                }
            }
        }
    }

    #[test]
    fn borders_never_exceed_half_of_the_fitted_slot() {
        let mut app = styled_app(HotbarSlotStyle {
            border_width: 30.0,
            selected_border_width: 40.0,
            ..default()
        });
        let window = app
            .world_mut()
            .spawn((
                Window {
                    resolution: (132, 600).into(),
                    ..default()
                },
                bevy::window::PrimaryWindow,
            ))
            .id();
        app.update();
        // 132 - 32 of margin - two 4px gaps leaves 92 for three slots.
        let size = (132.0_f32 - 32.0 - 2.0 * 4.0) / 3.0;
        let world = app.world_mut();
        for node in world
            .query_filtered::<&Node, With<HotbarSlot>>()
            .iter(world)
        {
            assert_eq!(node.width, px(size));
            assert_eq!(node.border, UiRect::all(px(size / 2.0)));
        }
        // A wide window fits the preferred 50px, so the widths apply unclamped.
        app.world_mut()
            .get_mut::<Window>(window)
            .unwrap()
            .resolution
            .set(800.0, 600.0);
        app.update();
        let slots = slots(&mut app);
        assert_eq!(slots[0].0, UiRect::all(Val::Px(25.0)));
        assert_eq!(slots[1].0, UiRect::all(Val::Px(25.0)));
    }

    #[test]
    fn slot_style_resource_is_optional() {
        let mut app = styled_app(HotbarSlotStyle {
            border_width: 7.0,
            selected_border_width: 7.0,
            border_color: BORDER,
            selected_border_color: BORDER,
            ..default()
        });
        // Removed before Startup: slots spawn with the defaults.
        app.world_mut().remove_resource::<HotbarSlotStyle>();
        app.update();
        app.update();
        for (border, border_color, _) in slots(&mut app) {
            assert_eq!(border, UiRect::all(Val::Px(2.0)));
            assert_eq!(border_color, color([0.6, 0.6, 0.6, 0.6]));
        }
        // Inserted later: picked up on the next frame.
        app.insert_resource(HotbarSlotStyle {
            border_width: 5.0,
            ..default()
        });
        app.update();
        assert_eq!(slots(&mut app)[1].0, UiRect::all(Val::Px(5.0)));
    }

    #[test]
    fn slots_without_inventory_content_are_never_faded() {
        let mut app = styled_app(HotbarSlotStyle {
            empty_slot_alpha: 0.1,
            ..default()
        });
        app.update();
        app.update();
        let slots = slots(&mut app);
        assert_eq!(slots[1].1, color([0.6, 0.6, 0.6, 0.6]));
        assert_eq!(slots[1].2, Color::srgba(0.15, 0.15, 0.15, 0.85));
    }
}