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
use bevy::prelude::*;
use woodpecker_ui::prelude::*;
/// A list of classes our widgets will use
/// Ideally these are scoped to a SINGLE widget.
/// As in styles should live with their widgets.
/// This example is primiarly meant to serve as a
/// resuable pattern. This also cuts down on boilerplate
/// within the widget spawning code itself. Again
/// this is not an endorsement for global styles rather
/// this serves as an example of how you might reference
/// multiple styles "classes" in a single widget.
/// This is useful for focus, hover, click style changes
/// and other things.
mod classes {
#![allow(non_upper_case_globals)]
use bevy::prelude::*;
use woodpecker_ui::prelude::*;
/// Styles for our main app widget.
pub const app_styles: WoodpeckerStyle = WoodpeckerStyle {
flex_direction: WidgetFlexDirection::Column,
..WoodpeckerStyle::DEFAULT
};
/// Red text styles
pub const red_text: WoodpeckerStyle = WoodpeckerStyle {
color: Color::Srgba(Srgba::RED),
..WoodpeckerStyle::DEFAULT
};
/// Blue text styles
pub const blue_text: WoodpeckerStyle = WoodpeckerStyle {
color: Color::Srgba(Srgba::BLUE),
..WoodpeckerStyle::DEFAULT
};
/// Green text styles
pub const green_text: WoodpeckerStyle = WoodpeckerStyle {
color: Color::Srgba(Srgba::GREEN),
..WoodpeckerStyle::DEFAULT
};
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_systems(Startup, startup)
.run();
}
fn startup(mut commands: Commands, mut ui_context: ResMut<WoodpeckerContext>) {
commands.spawn((Camera2d, WoodpeckerView));
let root = commands
.spawn((
WoodpeckerApp,
classes::app_styles,
WidgetChildren::default()
.with_child::<Element>((
Element,
classes::red_text,
WidgetRender::Text {
content: "Hello, I am red text!".into(),
},
))
.with_child::<Element>((
Element,
classes::blue_text,
WidgetRender::Text {
content: "Hello, I am blue text!".into(),
},
))
.with_child::<Element>((
Element,
classes::green_text,
WidgetRender::Text {
content: "Hello, I am green text!".into(),
},
)),
))
.id();
ui_context.set_root_widget(root);
}