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//! Now only some packaged candies are generated, no additional functions, maybe they will be added later,
5//! a plugin is reserved, but it has not been used yet
6//!
7//!
8//! # UI Layout Overview
9//!
10//! This crate defines a menu bar container using a horizontal stack layout:
11//!
12//! ```rust
13//! use bevy::prelude::*;
14//! use swoop_ui::prelude::*;
15//!
16//! fn setup(mut commands: Commands) {
17//! commands.spawn((
18//! HStack::new(AlignItems::Start, Val::Auto)
19//! .background_color(Srgba::WHITE.into())
20//! .justify_content(JustifyContent::Start)
21//! .pack(),
22//! ));
23//! }
24//! ```
25//!
26//! - `HStack` creates a horizontal layout with children aligned at the top.
27//! - The background color is set using the impl Into<Color> value.
28//! - Contents are left-aligned using `JustifyContent::Start`.
29//!
30//! Because the impl Bundle is implemented, it can be directly generated using commands.spawn
31
32use std::borrow::Cow;
33use std::fmt::Debug;
34
35use bevy_app::prelude::*;
36use bevy_ecs::prelude::*;
37use bevy_ui::prelude::*;
38
39// Background UI trait
40pub mod background;
41// Border UI trait
42pub mod border;
43// Shadow UI Trait
44pub mod shadow;
45
46/// Button
47pub mod button;
48/// Layouts and containers
49pub mod container;
50
51pub mod prelude {
52 pub use super::background::*;
53 pub use super::border::*;
54 pub use super::button::prelude::*;
55 pub use super::container::prelude::*;
56 pub use super::shadow::*;
57 pub use super::{SwoopUiPlugin, View};
58}
59
60/// Reserved for future addition of system functions
61pub struct SwoopUiPlugin;
62
63/// Provides common builder-style methods for UI configuration
64pub trait View: Bundle + Debug + Clone + Default {
65 /// Short Default Method
66 fn new() -> Self {
67 Self::default()
68 }
69
70 fn from_name(name: impl Into<Cow<'static, str>>) -> Self {
71 let mut view = Self::default();
72 view.name_node().set(name);
73 view
74 }
75
76 /// Returns a mutable reference to the entity's Name component
77 fn name_node(&mut self) -> &mut Name;
78
79 /// Returns a mutable reference to the entity's Node component
80 fn node_node(&mut self) -> &mut Node;
81
82 /// Sets the Name component
83 fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self {
84 self.name_node().set(name);
85 self
86 }
87
88 /// Applies padding to the Node
89 fn padding(mut self, padding: UiRect) -> Self {
90 self.node_node().padding = padding;
91 self
92 }
93
94 /// Sets width and height of the Node
95 fn frame(mut self, width: Val, height: Val) -> Self {
96 let node = self.node_node();
97 node.width = width;
98 node.height = height;
99 self
100 }
101
102 /// Sets the width of the Node
103 fn width(mut self, width: Val) -> Self {
104 self.node_node().width = width;
105 self
106 }
107
108 /// Sets the height of the Node
109 fn height(mut self, height: Val) -> Self {
110 self.node_node().height = height;
111 self
112 }
113}
114
115impl Plugin for SwoopUiPlugin {
116 fn build(&self, _: &mut App) {}
117}