1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! A [`Widget`] describe what you want to present onto the screen. `agape` tries to
//! provide as many [`Widget`]'s as possible for various uses such as [`Text`],[`Button`],
//! [`HStack`] and [`VStack`], and so on. There are two ways of creating widgets.
//!
//! ## Wrap another widget
//! For most simple use cases, you may wrap another widget in a function.
//!
//! ```
//! use agape::{widgets::*,Color};
//!
//! fn CtaButton() -> impl Widget{
//! Button::text("Get started")
//! .background_color(Color::rgb(100,25,255))
//! .padding(16)
//! .corner_radius(12)
//! }
//! ```
//!
//! Widgets use the [builder pattern](https://refactoring.guru/design-patterns/builder) to
//! configure properties, most widgets will have extra properties that can be configured,
//! check their docs.
//!
//! ## `#[derive(Widget)]`
//! For widgets that need to react and manage state the [`Widget`] derive macro is provided,
//! the widget will need a [`GlobalId`] and a child widget.
//!
//! ```
//! use agape::{Widget, widgets::{HStack,Button}, GlobalId, hstack};
//!
//! #[derive(Widget)]
//! struct Menu{
//! id: GlobalId,
//! #[child]
//! child: HStack
//! }
//!
//! impl Menu{
//! pub fn new() -> Self{
//! let child = hstack![
//! Button::text("File"),
//! Button::text("Edit"),
//! Button::text("View"),
//! Button::text("About"),
//! ]
//! .spacing(12)
//! .padding(16);
//!
//! Self{
//! id: GlobalId::new(),
//! child
//! }
//! }
//! }
//! ```
//!
//! State is handled using messages, a [`Message`] is any rust struct that implements
//! `Any + Debug`, by using messages coupling is reduces and widgets are able to be
//! more independent. To make a widget stateful, i.e. to react to messages, use the
//! `#[interactive]` attribute.
//!
//! ```
//! use agape::{Widget, GlobalId, widgets::{Button,Text}, hstack, MessageQueue};
//! use agape::widgets::HStack;
//!
//!
//! #[derive(Debug,Copy, Clone)]
//! struct Marco;
//! #[derive(Debug,Copy, Clone)]
//! struct Polo;
//!
//! #[derive(Widget)]
//! #[interactive]
//! struct Menu{
//! id: GlobalId,
//! #[child]
//! child: HStack
//! }
//!
//! impl Menu{
//! pub fn new() -> Self{
//! let child = hstack![
//! Button::text("Marco")
//! .on_click(|messages|messages.add(Marco)),
//! Button::text("Polo")
//! .on_click(|messages|messages.add(Polo))
//! ];
//!
//! Self{
//! id: GlobalId::new(),
//! child
//! }
//! }
//!
//! pub fn update(&mut self, messages: &mut MessageQueue){
//! if messages.has::<Marco>(){
//! println!("Marco!")
//! }
//!
//! if messages.has::<Polo>(){
//! println!("Polo!")
//! }
//! }
//! }
//! ```
use crateAssetManager;
use crateMessageQueue;
use GlobalId;
use Layout;
use Renderer;
pub use *;
pub use Container;
pub use *;
pub use Icon;
pub use Image;
pub use *;
pub use Svg;
pub use Text;
pub use TextField;
pub use *;
/// A `Widget` is anything that can ultimately be drawn to the screen. Widgets internally
/// can be composed of anything, but each widget must have a [`GlobalId`] and a [`Layout`].
/// See the [module docs] for more info.
///
/// [module docs]: crate::widgets
/// An iterator over a tree of widgets.