bevy_pages 0.1.0

A lightweight and elegant framework to upgrade your Bevy UI experience.
Documentation
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
#![allow(clippy::type_complexity)]

use crate::page::Page;
use crate::spawner::PageSpawner;
use bevy::app::{App, Plugin, Update};
use bevy::asset::{AssetApp, AssetEvent};
use bevy::prelude::{IntoScheduleConfigs, on_message};

/// Contains the basic element structures for a clean UI.
pub mod element;

/// Contains UI events and event handling systems.
pub mod events;

/// Contains the page asset loader.
pub mod loader;

/// Contains the [Page] struct for core UI work.
pub mod page;

/// Contains the [PageSpawner] resource and related systems to spawn UI pages.
pub mod spawner;

mod color;

mod parser;

/// The main plugin for `bevy_pages`.
///
/// This is required to spawn and manage UI pages.
pub struct PagesPlugin {
    /// The initial read capacity for the asset loading process.
    ///
    /// This should be the average size (in bytes) of the XML files you plan to load.
    ///
    /// Defaults to `2048`.
    pub initial_read_capacity: usize,
}

impl Plugin for PagesPlugin {
    fn build(&self, app: &mut App) {
        app.init_asset::<Page>()
            .register_asset_loader(loader::PageLoader {
                initial_read_capacity: self.initial_read_capacity,
            })
            .insert_resource(PageSpawner::new())
            .add_systems(Update, events::interactions)
            .add_systems(
                Update,
                spawner::spawn_page.run_if(on_message::<AssetEvent<Page>>),
            )
            .add_observer(spawner::despawn_page);
    }
}

impl Default for PagesPlugin {
    fn default() -> Self {
        Self {
            initial_read_capacity: 2048,
        }
    }
}