swoop_ui/
lib.rs

1//! **Swoop UI** is a modular, ergonomic layout toolkit built on top of Bevy UI.
2//! It introduces expressive layout containers like `HStack`, `VStack`, `HGrid`, and `VGrid`,
3//! supporting fluent syntax for padding, spacing, border, and background styling.
4//!
5//! # UI Layout Overview
6//!
7//! This crate defines a menu bar container using a horizontal stack layout:
8//!
9//! ```rust
10//! use bevy::prelude::*;
11//! use swoop_ui::prelude::*;
12//!
13//! fn setup(mut commands: Commands) {
14//!     commands.spawn((
15//!         HStack::new(AlignItems::Start, Val::Auto)
16//!             .background_color(Srgba::WHITE.into())
17//!             .justify_content(JustifyContent::Start)
18//!             .pack(),
19//!     ));
20//! }
21//! ```
22//!
23//! - `HStack` creates a horizontal layout with children aligned at the top.
24//! - The background color is set using the `MENU_BAR_BACKGROUND` value for theme consistency.
25//! - Contents are left-aligned using `JustifyContent::Start`.
26//!
27//! The layout is finalized with `.pack()` and passed into `commands.spawn` to be registered in the entity world.
28
29use std::borrow::Cow;
30
31use bevy_app::prelude::*;
32use bevy_ecs::prelude::*;
33use bevy_ui::prelude::*;
34
35/// Layouts and containers
36pub mod container;
37
38pub mod prelude {
39    pub use super::container::prelude::*;
40    pub use super::{SwoopUiPlugin, UiBase, UiToBundle};
41}
42
43/// Reserved for future addition of system functions
44pub struct SwoopUiPlugin;
45
46/// Provides common builder-style methods for UI configuration
47pub trait UiBase {
48    /// Returns a mutable reference to the entity's Name component
49    fn name_node(&mut self) -> &mut Name;
50
51    /// Returns a mutable reference to the entity's Node component
52    fn node_node(&mut self) -> &mut Node;
53
54    /// Sets the Name component
55    fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self
56    where
57        Self: Sized,
58    {
59        self.name_node().set(name);
60        self
61    }
62
63    /// Applies padding to the Node
64    fn padding(mut self, padding: UiRect) -> Self
65    where
66        Self: Sized,
67    {
68        self.node_node().padding = padding;
69        self
70    }
71
72    /// Sets width and height of the Node
73    fn frame(mut self, width: Val, height: Val) -> Self
74    where
75        Self: Sized,
76    {
77        let node = self.node_node();
78        node.width = width;
79        node.height = height;
80        self
81    }
82
83    /// Sets the width of the Node
84    fn width(mut self, width: Val) -> Self
85    where
86        Self: Sized,
87    {
88        self.node_node().width = width;
89        self
90    }
91
92    /// Sets the height of the Node
93    fn height(mut self, height: Val) -> Self
94    where
95        Self: Sized,
96    {
97        self.node_node().height = height;
98        self
99    }
100}
101
102/// Converts a custom UI builder into a Bevy-compatible Bundle
103pub trait UiToBundle {
104    /// Consumes the UI builder and produces a bundle
105    fn pack(self) -> impl Bundle;
106}
107
108impl Plugin for SwoopUiPlugin {
109    fn build(&self, app: &mut App) {
110        todo!()
111    }
112}