swoop_ui/
lib.rs

1use std::borrow::Cow;
2
3use bevy_app::prelude::*;
4use bevy_ecs::prelude::*;
5use bevy_ui::prelude::*;
6
7pub mod container;
8
9pub mod prelude {
10    pub use super::container::prelude::*;
11    pub use super::{SwoopUiPlugin, UiBase, UiToBundle};
12}
13
14pub struct SwoopUiPlugin;
15
16/// Provides common builder-style methods for UI configuration
17pub trait UiBase {
18    /// Returns a mutable reference to the entity's Name component
19    fn name_node(&mut self) -> &mut Name;
20
21    /// Returns a mutable reference to the entity's Node component
22    fn node_node(&mut self) -> &mut Node;
23
24    /// Sets the Name component
25    fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self
26    where
27        Self: Sized,
28    {
29        self.name_node().set(name);
30        self
31    }
32
33    /// Applies padding to the Node
34    fn padding(mut self, padding: UiRect) -> Self
35    where
36        Self: Sized,
37    {
38        self.node_node().padding = padding;
39        self
40    }
41
42    /// Sets width and height of the Node
43    fn frame(mut self, width: Val, height: Val) -> Self
44    where
45        Self: Sized,
46    {
47        let node = self.node_node();
48        node.width = width;
49        node.height = height;
50        self
51    }
52
53    /// Sets the width of the Node
54    fn width(mut self, width: Val) -> Self
55    where
56        Self: Sized,
57    {
58        self.node_node().width = width;
59        self
60    }
61
62    /// Sets the height of the Node
63    fn height(mut self, height: Val) -> Self
64    where
65        Self: Sized,
66    {
67        self.node_node().height = height;
68        self
69    }
70}
71
72/// Converts a custom UI builder into a Bevy-compatible Bundle
73pub trait UiToBundle {
74    /// Consumes the UI builder and produces a bundle
75    fn pack(self) -> impl Bundle;
76}
77
78impl Plugin for SwoopUiPlugin {
79    fn build(&self, app: &mut App) {
80        todo!()
81    }
82}