Crate bevy_ui_mod_alerts

Source
Expand description

bevy_ui_mod_alerts provides a “toast”-like alert UI which can be used to help manage errors using a convenient UI.

Alerts can be spawned by directly spawning AlertBundles using AlertBundle or Alert::bundle, or by piping a Vec<String> of alert messages into the AlertsPlugin::alert system.

§Examples

This example pipes some arbitrary system into the AlertsPlugin::alert system:

use bevy::prelude::*;
use bevy_ui_mod_alerts::{AlertsPlugin};

fn main() {
    let mut app = App::new();
    app.add_plugins(MinimalPlugins);
    app.add_plugins(AlertsPlugin::new());
    app.add_systems(Update, do_stuff_and_maybe_alert.pipe(AlertsPlugin::alert));
    // app.run();
}

#[derive(Component)]
struct MyComponent;

fn do_stuff_and_maybe_alert(my_query: Query<&MyComponent>) -> Vec<String> {
    vec![]
}

The resulting UI is somewhat restylable but may not fit every application. Users can restyle the alerts with the AlertElements resource:

use bevy::prelude::*;
use bevy_ui_mod_alerts::{AlertMarker, AlertElements};

let mut app = App::new();
// ...
app.insert_resource(AlertElements::<AlertMarker> {
    // root: NodeBundle
    // alert: NodeBundle
    // header: NodeBundle
    // body: NodeBundle
    // text: TextStyle
    ..Default::default()
});

Or make tweaks from the default:

use bevy::prelude::Color;
use bevy::color::palettes;
use bevy_ui_mod_alerts::AlertElements;
let mut elements = AlertElements::new();
elements.header.background_color.0 = Color::Srgba(palettes::css::GREEN);

…but it is not the most convenient to do so yet.

Additionally, if users want multiple different alert styles to exist simultaneously, the type parameter M can be set to a custom component. Typically, the default AlertMarker is used.

use bevy::prelude::*;
use bevy_ui_mod_alerts::AlertsPlugin;

#[derive(Component, Default, Reflect)]
struct MyAlert;

let mut app = App::new();
app.add_plugins(AlertsPlugin::<MyAlert>::default());
app.add_systems(Update, (|| { vec![] }).pipe(AlertsPlugin::<MyAlert>::custom_alert));

Structs§

Alert
A component representing an alert message that should be displayed in a UI.
AlertElements
A type collecting the UI styles and presentational logic of each possible alert UI element.
AlertLifetime
A wrapper for the Duration that Alerts of this kind stay alive before transitioning out of the scene.
AlertMarker
A default marker component for use with the default styles.
AlertSystems
The SystemSet in which alerts-related systems are run.
AlertTimer
A timer that tracks the current lifetime
AlertUi
A marker component for Alerts that have UI components added and children spawned.
AlertUiRoot
A marker copmonent for the root node of the alerts UI.
AlertsPlugin
A Bevy plugin that must be attached in order to spawn alert UIs.
DismissButton
A marker component for the button in the AlertUI node tree that dismisses the alert.
MaxAlerts
The maximum number of Alert UI nodes that can be shown in the UI at once.
TransitionTimer
A timer for AlertTransitions.

Enums§

AlertTransition
A flag that determines how the Alert transitions in and out of the UI.

Constants§

ALERT_Z_INDEX
DEFAULT_ALERT_HEIGHT