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
use bevy::prelude::*;
use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
// .add_plugins((
// bevy_inspector_egui::bevy_egui::EguiPlugin {
// enable_multipass_for_primary_context: false,
// },
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
// ))
.add_systems(Startup, startup)
.run();
}
fn startup(
mut commands: Commands,
mut ui_context: ResMut<WoodpeckerContext>,
asset_server: Res<AssetServer>,
) {
commands.spawn((Camera2d, WoodpeckerView));
let root = commands
.spawn((
WoodpeckerApp,
WidgetChildren::default().with_child::<WindowingContextProvider>(
WidgetChildren::default()
.with_child::<WoodpeckerWindow>((
WoodpeckerWindow {
title: "Image/SVG fits to content.".into(),
initial_position: Vec2::new(200.0, 200.0),
window_styles: WoodpeckerStyle {
min_width: 400.0.into(),
opacity: 0.75,
..WoodpeckerWindow::default().window_styles
},
..Default::default()
},
PassedChildren(WidgetChildren::default().with_child::<Element>((
Element,
WoodpeckerStyle {
align_items: Some(WidgetAlignItems::Center),
flex_direction: WidgetFlexDirection::Column,
padding: Edge::all(10.0),
width: Units::Percentage(100.0).into(),
..Default::default()
},
WidgetChildren::default().with_child::<Element>((
Element,
WoodpeckerStyle {
width: Units::Auto,
height: Units::Pixels(200.0),
margin: Edge::all(0.0).bottom(10.0),
..Default::default()
},
WidgetRender::Image {
handle: asset_server.load("woodpecker.jpg"),
},
)),
))),
))
.with_child::<WoodpeckerWindow>((
WoodpeckerWindow {
title: "2nd window".into(),
initial_position: Vec2::new(200.0, 200.0),
window_styles: WoodpeckerStyle {
min_width: 400.0.into(),
opacity: 0.75,
..WoodpeckerWindow::default().window_styles
},
..Default::default()
},
PassedChildren(WidgetChildren::default().with_child::<Element>((
Element,
WoodpeckerStyle {
align_items: Some(WidgetAlignItems::Center),
flex_direction: WidgetFlexDirection::Column,
padding: Edge::all(10.0),
width: Units::Percentage(100.0).into(),
..Default::default()
},
WidgetChildren::default().with_child::<Element>((
Element,
WoodpeckerStyle {
width: Units::Auto,
height: Units::Pixels(200.0),
..Default::default()
},
WidgetRender::Svg {
handle: asset_server.load("woodpecker_svg/woodpecker.svg"),
color: Some(Srgba::RED.into()),
},
)),
))),
)),
),
))
.id();
ui_context.set_root_widget(root);
}