snow_ui/
lib.rs

1// Minimal mock of an `snow_ui` crate used by the example in `main.rs`.
2// Provides the types and items referenced by the example so the crate builds.
3
4pub mod prelude {
5    pub use super::{
6        Board, Card, CENTER, MIDDLE, Row, Text, TextTimer, VIEWPORT_HEIGHT, VIEWPORT_WIDTH, World,
7        Widget, IntoWidget, Girl, HairColor, SkinColor, BodyType, Appearance, GirlActions,
8        HAlign, VAlign,
9    };
10
11    // Re-export the derive macro so examples can `use snow_ui::prelude::*` and write
12    // `#[derive(IntoWidget)]` without importing `snow_ui_macros` explicitly.
13    pub use snow_ui_macros::IntoWidget;
14
15    /// Helper to allow `..default()` shorthand in user code (like Bevy's prelude).
16    ///
17    /// Example: `Row { ..default() }`
18    #[allow(dead_code)]
19    pub fn default<T: Default>() -> T {
20        T::default()
21    }
22} 
23
24/// Launch the UI using a builder function that returns a `World`.
25///
26/// Example: `snow_ui::launch(world);` where `fn world() -> World { ... }`.
27pub fn launch<F: FnOnce() -> World>(builder: F) {
28    let world = builder();
29    println!("Launching snow_ui with world:\n{:#?}", world);
30}
31
32#[allow(dead_code)]
33#[derive(Debug)]
34pub struct World {
35    pub root: Widget,
36}
37
38impl Default for World {
39    fn default() -> Self {
40        Self {
41            root: Widget::Board(Board::default()),
42        }
43    }
44}
45
46#[allow(dead_code)]
47#[derive(Debug)]
48pub struct Board {
49    pub width: Size,
50    pub height: Size,
51    pub h_align: HAlign,
52    pub v_align: VAlign,
53    pub children: Vec<Card>,
54}
55
56impl Default for Board {
57    fn default() -> Self {
58        Self {
59            width: VIEWPORT_WIDTH,
60            height: VIEWPORT_HEIGHT,
61            h_align: HAlign::Center,
62            v_align: VAlign::Middle,
63            children: vec![],
64        }
65    }
66} 
67
68#[allow(dead_code)]
69#[derive(Debug)]
70pub struct Card {
71    pub children: Vec<Row>,
72}
73
74impl Default for Card {
75    fn default() -> Self {
76        Self { children: vec![] }
77    }
78}
79
80#[allow(dead_code)]
81#[derive(Debug)]
82pub struct Row {
83    pub children: Vec<Element>,
84}
85
86impl Default for Row {
87    fn default() -> Self {
88        Self { children: vec![] }
89    }
90}
91
92#[allow(dead_code)]
93#[derive(Debug)]
94pub enum Element {
95    Text(Text),
96    TextTimer(TextTimer),
97}
98
99#[allow(dead_code)]
100#[derive(Debug)]
101pub struct Text {
102    pub text: &'static str,
103}
104
105impl Text {
106    /// Return an `Element::Text` so the call sites using `Text::from_str` can be placed
107    /// directly inside a `Vec` of `Element`.
108    pub fn from_str(s: &'static str) -> Element {
109        Element::Text(Text { text: s })
110    }
111}
112
113impl Default for Text {
114    fn default() -> Self {
115        Self { text: "" }
116    }
117}
118
119impl From<Text> for Element {
120    fn from(t: Text) -> Self {
121        Element::Text(t)
122    }
123} 
124
125#[allow(dead_code)]
126#[derive(Debug)]
127pub struct TextTimer {
128    pub format: &'static str,
129}
130
131impl From<TextTimer> for Element {
132    fn from(t: TextTimer) -> Self {
133        Element::TextTimer(t)
134    }
135}
136
137impl TextTimer {
138    /// Construct a `TextTimer` with the provided format and return it as an `Element`.
139    ///
140    /// Use `TextTimer::with_format("%H:%M:%S")` to create a timer element.
141    pub fn with_format(format: &'static str) -> Element {
142        Element::TextTimer(TextTimer { format })
143    }
144}
145
146impl Default for TextTimer {
147    fn default() -> Self {
148        Self { format: "" }
149    }
150}
151
152#[allow(dead_code)]
153#[derive(Debug, Clone, Copy)]
154pub enum Size {
155    ViewportWidth,
156    ViewportHeight,
157}
158
159pub const VIEWPORT_WIDTH: Size = Size::ViewportWidth;
160pub const VIEWPORT_HEIGHT: Size = Size::ViewportHeight;
161
162#[allow(dead_code)]
163#[derive(Debug, Clone, Copy)]
164pub enum HAlign {
165    Left,
166    Center,
167    Right,
168}
169
170#[allow(dead_code)]
171#[derive(Debug, Clone, Copy)]
172pub enum VAlign {
173    Top,
174    Middle,
175    Bottom,
176}
177
178pub const CENTER: HAlign = HAlign::Center;
179pub const MIDDLE: VAlign = VAlign::Middle;
180
181// Widget system
182#[allow(dead_code)]
183#[derive(Debug)]
184pub enum Widget {
185    Board(Board),
186    Girl(Girl),
187}
188
189impl From<Board> for Widget {
190    fn from(b: Board) -> Self {
191        Widget::Board(b)
192    }
193}
194
195impl From<Girl> for Widget {
196    fn from(g: Girl) -> Self {
197        Widget::Girl(g)
198    }
199}
200
201pub trait IntoWidget {
202    fn into_widget(self) -> Widget;
203}
204
205impl<T: IntoWidget> From<T> for Widget {
206    fn from(t: T) -> Self {
207        t.into_widget()
208    }
209}
210
211
212// Girl component
213#[allow(dead_code)]
214#[derive(Debug, Default)]
215pub struct Girl {
216    pub hair_color: HairColor,
217    pub skin_color: SkinColor,
218    pub body_type: BodyType,
219    pub appearance: Appearance,
220    pub every_morning: Vec<GirlActions>,
221}
222
223#[allow(dead_code)]
224#[derive(Debug, Clone, Copy)]
225pub enum HairColor {
226    Black,
227    Brown,
228    Blonde,
229    Red,
230}
231
232impl Default for HairColor {
233    fn default() -> Self {
234        HairColor::Brown
235    }
236}
237
238#[allow(dead_code)]
239#[derive(Debug, Clone, Copy)]
240pub enum SkinColor {
241    Yellow,
242    Light,
243    Dark,
244}
245
246impl Default for SkinColor {
247    fn default() -> Self {
248        SkinColor::Light
249    }
250}
251
252#[allow(dead_code)]
253#[derive(Debug, Clone, Copy)]
254pub enum BodyType {
255    Slim,
256    Average,
257    Curvy,
258}
259
260impl Default for BodyType {
261    fn default() -> Self {
262        BodyType::Average
263    }
264}
265
266#[allow(dead_code)]
267#[derive(Debug, Clone, Copy)]
268pub enum Appearance {
269    Beautiful,
270    Cute,
271    Plain,
272}
273
274impl Default for Appearance {
275    fn default() -> Self {
276        Appearance::Cute
277    }
278}
279
280#[allow(dead_code)]
281#[derive(Debug, Clone, Copy)]
282pub enum GirlActions {
283    SayHi,
284    PrepareBreakfast,
285}