Skip to content

Commit 6507ba9

Browse files
committed
Port bevy_ui on pipelined_rendering
1 parent 43e8a15 commit 6507ba9

25 files changed

+2761
-0
lines changed

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ default = [
3131
"bevy_sprite2",
3232
"bevy_render2",
3333
"bevy_pbr2",
34+
"bevy_ui2",
3435
"bevy_winit",
3536
"render",
3637
"png",
@@ -64,6 +65,7 @@ bevy_render2 = ["bevy_internal/bevy_render2"]
6465
bevy_sprite2 = ["bevy_internal/bevy_sprite2"]
6566
bevy_pbr2 = ["bevy_internal/bevy_pbr2"]
6667
bevy_gltf2 = ["bevy_internal/bevy_gltf2"]
68+
bevy_ui2 = ["bevy_internal/bevy_ui2"]
6769

6870
trace_chrome = ["bevy_internal/trace_chrome"]
6971
trace = ["bevy_internal/trace"]
@@ -502,6 +504,10 @@ path = "examples/ui/text_debug.rs"
502504
name = "ui"
503505
path = "examples/ui/ui.rs"
504506

507+
[[example]]
508+
name = "ui_pipelined"
509+
path = "examples/ui/ui_pipelined.rs"
510+
505511
# Window
506512
[[example]]
507513
name = "clear_color"

crates/bevy_internal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ bevy_sprite = { path = "../bevy_sprite", optional = true, version = "0.5.0" }
7878
bevy_sprite2 = { path = "../../pipelined/bevy_sprite2", optional = true, version = "0.5.0" }
7979
bevy_text = { path = "../bevy_text", optional = true, version = "0.5.0" }
8080
bevy_ui = { path = "../bevy_ui", optional = true, version = "0.5.0" }
81+
bevy_ui2 = { path = "../../pipelined/bevy_ui2", optional = true, version = "0.5.0" }
8182
bevy_wgpu = { path = "../bevy_wgpu", optional = true, version = "0.5.0" }
8283
bevy_winit = { path = "../bevy_winit", optional = true, version = "0.5.0" }
8384
bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.5.0" }

crates/bevy_internal/src/default_plugins.rs

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ impl PluginGroup for PipelinedDefaultPlugins {
136136

137137
#[cfg(feature = "bevy_gltf2")]
138138
group.add(bevy_gltf2::GltfPlugin::default());
139+
140+
#[cfg(feature = "bevy_ui2")]
141+
group.add(bevy_ui2::UiPlugin::default());
139142
}
140143

141144
#[cfg(feature = "bevy_winit")]

crates/bevy_internal/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ pub mod ui {
153153
pub use bevy_ui::*;
154154
}
155155

156+
#[cfg(feature = "bevy_ui2")]
157+
pub mod ui2 {
158+
//! User interface components and widgets.
159+
pub use bevy_ui2::*;
160+
}
161+
156162
#[cfg(feature = "bevy_winit")]
157163
pub mod winit {
158164
pub use bevy_winit::*;

examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ Example | File | Description
251251
`text` | [`ui/text.rs`](./ui/text.rs) | Illustrates creating and updating text
252252
`text_debug` | [`ui/text_debug.rs`](./ui/text_debug.rs) | An example for debugging text layout
253253
`ui` | [`ui/ui.rs`](./ui/ui.rs) | Illustrates various features of Bevy UI
254+
`ui_pipelined` | [`ui/ui_pipelined.rs`](./ui/ui_pipelined.rs) | Illustrates various features of Bevy UI
254255

255256
## Window
256257

examples/ui/ui_pipelined.rs

+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
use bevy::{
2+
prelude::{App, AssetServer, BuildChildren, Commands, Rect, Res, Size},
3+
render2::{camera::OrthographicCameraBundle, color::Color},
4+
ui2::{
5+
entity::ImageBundle, entity::NodeBundle, entity::UiCameraBundle, AlignItems,
6+
JustifyContent, PositionType, Style, Val,
7+
},
8+
PipelinedDefaultPlugins,
9+
};
10+
11+
/// This example illustrates the various features of Bevy UI.
12+
fn main() {
13+
App::new()
14+
.add_plugins(PipelinedDefaultPlugins)
15+
.add_startup_system(setup)
16+
.run();
17+
}
18+
19+
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
20+
// ui camera
21+
commands.spawn_bundle(UiCameraBundle::default());
22+
// FIXME: this is needed to clear the background root node
23+
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
24+
commands
25+
.spawn_bundle(NodeBundle {
26+
style: Style {
27+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
28+
justify_content: JustifyContent::SpaceBetween,
29+
..Default::default()
30+
},
31+
color: Color::NONE,
32+
..Default::default()
33+
})
34+
.with_children(|parent| {
35+
// left vertical fill (border)
36+
parent
37+
.spawn_bundle(NodeBundle {
38+
style: Style {
39+
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
40+
border: Rect::all(Val::Px(2.0)),
41+
..Default::default()
42+
},
43+
color: Color::rgb(0.65, 0.65, 0.65),
44+
..Default::default()
45+
})
46+
.with_children(|parent| {
47+
// left vertical fill (content)
48+
parent
49+
.spawn_bundle(NodeBundle {
50+
style: Style {
51+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
52+
align_items: AlignItems::FlexEnd,
53+
..Default::default()
54+
},
55+
color: Color::rgb(0.15, 0.15, 0.15),
56+
..Default::default()
57+
})
58+
.with_children(|_parent| {
59+
// text
60+
// parent.spawn_bundle(TextBundle {
61+
// style: Style {
62+
// margin: Rect::all(Val::Px(5.0)),
63+
// ..Default::default()
64+
// },
65+
// text: Text::with_section(
66+
// "Text Example",
67+
// TextStyle {
68+
// font: asset_server.load("fonts/FiraSans-Bold.ttf"),
69+
// font_size: 30.0,
70+
// color: Color::WHITE,
71+
// },
72+
// Default::default(),
73+
// ),
74+
// ..Default::default()
75+
// });
76+
});
77+
});
78+
// right vertical fill
79+
parent.spawn_bundle(NodeBundle {
80+
style: Style {
81+
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
82+
..Default::default()
83+
},
84+
color: Color::rgb(0.15, 0.15, 0.15),
85+
..Default::default()
86+
});
87+
// absolute positioning
88+
parent
89+
.spawn_bundle(NodeBundle {
90+
style: Style {
91+
size: Size::new(Val::Px(200.0), Val::Px(200.0)),
92+
position_type: PositionType::Absolute,
93+
position: Rect {
94+
left: Val::Px(210.0),
95+
bottom: Val::Px(10.0),
96+
..Default::default()
97+
},
98+
border: Rect::all(Val::Px(20.0)),
99+
..Default::default()
100+
},
101+
color: Color::rgb(0.4, 0.4, 1.0),
102+
..Default::default()
103+
})
104+
.with_children(|parent| {
105+
parent.spawn_bundle(NodeBundle {
106+
style: Style {
107+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
108+
..Default::default()
109+
},
110+
color: Color::rgb(0.8, 0.8, 1.0),
111+
..Default::default()
112+
});
113+
});
114+
// render order test: reddest in the back, whitest in the front (flex center)
115+
parent
116+
.spawn_bundle(NodeBundle {
117+
style: Style {
118+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
119+
position_type: PositionType::Absolute,
120+
align_items: AlignItems::Center,
121+
justify_content: JustifyContent::Center,
122+
..Default::default()
123+
},
124+
color: Color::NONE,
125+
..Default::default()
126+
})
127+
.with_children(|parent| {
128+
parent
129+
.spawn_bundle(NodeBundle {
130+
style: Style {
131+
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
132+
..Default::default()
133+
},
134+
color: Color::rgb(1.0, 0.0, 0.0),
135+
..Default::default()
136+
})
137+
.with_children(|parent| {
138+
parent.spawn_bundle(NodeBundle {
139+
style: Style {
140+
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
141+
position_type: PositionType::Absolute,
142+
position: Rect {
143+
left: Val::Px(20.0),
144+
bottom: Val::Px(20.0),
145+
..Default::default()
146+
},
147+
..Default::default()
148+
},
149+
color: Color::rgb(1.0, 0.3, 0.3),
150+
..Default::default()
151+
});
152+
parent.spawn_bundle(NodeBundle {
153+
style: Style {
154+
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
155+
position_type: PositionType::Absolute,
156+
position: Rect {
157+
left: Val::Px(40.0),
158+
bottom: Val::Px(40.0),
159+
..Default::default()
160+
},
161+
..Default::default()
162+
},
163+
color: Color::rgb(1.0, 0.5, 0.5),
164+
..Default::default()
165+
});
166+
parent.spawn_bundle(NodeBundle {
167+
style: Style {
168+
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
169+
position_type: PositionType::Absolute,
170+
position: Rect {
171+
left: Val::Px(60.0),
172+
bottom: Val::Px(60.0),
173+
..Default::default()
174+
},
175+
..Default::default()
176+
},
177+
color: Color::rgb(1.0, 0.7, 0.7),
178+
..Default::default()
179+
});
180+
// alpha test
181+
parent.spawn_bundle(NodeBundle {
182+
style: Style {
183+
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
184+
position_type: PositionType::Absolute,
185+
position: Rect {
186+
left: Val::Px(80.0),
187+
bottom: Val::Px(80.0),
188+
..Default::default()
189+
},
190+
..Default::default()
191+
},
192+
color: Color::rgba(1.0, 0.9, 0.9, 0.4),
193+
..Default::default()
194+
});
195+
});
196+
});
197+
// bevy logo (flex center)
198+
parent
199+
.spawn_bundle(NodeBundle {
200+
style: Style {
201+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
202+
position_type: PositionType::Absolute,
203+
justify_content: JustifyContent::Center,
204+
align_items: AlignItems::FlexEnd,
205+
..Default::default()
206+
},
207+
color: Color::NONE,
208+
..Default::default()
209+
})
210+
.with_children(|parent| {
211+
// bevy logo (image)
212+
parent.spawn_bundle(ImageBundle {
213+
style: Style {
214+
size: Size::new(Val::Px(500.0), Val::Auto),
215+
..Default::default()
216+
},
217+
texture: Some(asset_server.load("branding/bevy_logo_dark_big.png")),
218+
..Default::default()
219+
});
220+
});
221+
});
222+
}

pipelined/bevy_ui2/Cargo.toml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "bevy_ui2"
3+
version = "0.5.0"
4+
edition = "2018"
5+
authors = [
6+
"Bevy Contributors <bevyengine@gmail.com>",
7+
"Carter Anderson <mcanders1@gmail.com>",
8+
]
9+
description = "A custom ECS-driven UI framework built specifically for Bevy Engine"
10+
homepage = "https://bevyengine.org"
11+
repository = "https://github.com/bevyengine/bevy"
12+
license = "MIT OR Apache-2.0"
13+
keywords = ["bevy"]
14+
15+
[dependencies]
16+
# bevy
17+
bevy_app = { path = "../../crates/bevy_app", version = "0.5.0" }
18+
bevy_asset = { path = "../../crates/bevy_asset", version = "0.5.0" }
19+
bevy_core = { path = "../../crates/bevy_core", version = "0.5.0" }
20+
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.5.0" }
21+
bevy_derive = { path = "../../crates/bevy_derive", version = "0.5.0" }
22+
bevy_ecs = { path = "../../crates/bevy_ecs", version = "0.5.0" }
23+
bevy_input = { path = "../../crates/bevy_input", version = "0.5.0" }
24+
bevy_log = { path = "../../crates/bevy_log", version = "0.5.0" }
25+
bevy_math = { path = "../../crates/bevy_math", version = "0.5.0" }
26+
bevy_reflect = { path = "../../crates/bevy_reflect", version = "0.5.0", features = ["bevy"] }
27+
bevy_render2 = { path = "../bevy_render2", version = "0.5.0" }
28+
#bevy_text = { path = "../../crates/bevy_text", version = "0.5.0" }
29+
bevy_transform = { path = "../../crates/bevy_transform", version = "0.5.0" }
30+
bevy_window = { path = "../../crates/bevy_window", version = "0.5.0" }
31+
bevy_utils = { path = "../../crates/bevy_utils", version = "0.5.0" }
32+
33+
# other
34+
stretch = "0.3.2"
35+
serde = {version = "1", features = ["derive"]}
36+
smallvec = { version = "1.6", features = ["union", "const_generics"] }
37+
crevice = { path = "../../crates/crevice", version = "0.6.0" }
38+
bytemuck = "1.5"
39+
wgpu = "0.11.0"

pipelined/bevy_ui2/src/anchors.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#[derive(Debug, Clone)]
2+
pub struct Anchors {
3+
pub left: f32,
4+
pub right: f32,
5+
pub bottom: f32,
6+
pub top: f32,
7+
}
8+
9+
impl Anchors {
10+
pub const BOTTOM_FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 0.0);
11+
pub const BOTTOM_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.0, 0.0);
12+
pub const BOTTOM_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.0, 0.0);
13+
pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5);
14+
pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0);
15+
pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5);
16+
pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0);
17+
pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5);
18+
pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5);
19+
pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0);
20+
pub const FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 1.0);
21+
pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0);
22+
pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0);
23+
pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0);
24+
pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0);
25+
pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0);
26+
27+
pub const fn new(left: f32, right: f32, bottom: f32, top: f32) -> Self {
28+
Anchors {
29+
left,
30+
right,
31+
bottom,
32+
top,
33+
}
34+
}
35+
}
36+
37+
impl Default for Anchors {
38+
fn default() -> Self {
39+
Anchors {
40+
left: 0.0,
41+
right: 0.0,
42+
bottom: 0.0,
43+
top: 0.0,
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)