-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
use bevy::{ | ||
prelude::{App, AssetServer, BuildChildren, Commands, Rect, Res, Size}, | ||
render2::{camera::OrthographicCameraBundle, color::Color}, | ||
ui2::{ | ||
entity::ImageBundle, entity::NodeBundle, entity::UiCameraBundle, AlignItems, | ||
JustifyContent, PositionType, Style, Val, | ||
}, | ||
PipelinedDefaultPlugins, | ||
}; | ||
|
||
/// This example illustrates the various features of Bevy UI. | ||
fn main() { | ||
App::new() | ||
.add_plugins(PipelinedDefaultPlugins) | ||
.add_startup_system(setup) | ||
.run(); | ||
} | ||
|
||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
// ui camera | ||
commands.spawn_bundle(UiCameraBundle::default()); | ||
// FIXME: this is needed to clear the background root node | ||
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | ||
commands | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
justify_content: JustifyContent::SpaceBetween, | ||
..Default::default() | ||
}, | ||
color: Color::NONE, | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
// left vertical fill (border) | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)), | ||
border: Rect::all(Val::Px(2.0)), | ||
..Default::default() | ||
}, | ||
color: Color::rgb(0.65, 0.65, 0.65), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
// left vertical fill (content) | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
align_items: AlignItems::FlexEnd, | ||
..Default::default() | ||
}, | ||
color: Color::rgb(0.15, 0.15, 0.15), | ||
..Default::default() | ||
}) | ||
.with_children(|_parent| { | ||
// text | ||
// parent.spawn_bundle(TextBundle { | ||
// style: Style { | ||
// margin: Rect::all(Val::Px(5.0)), | ||
// ..Default::default() | ||
// }, | ||
// text: Text::with_section( | ||
// "Text Example", | ||
// TextStyle { | ||
// font: asset_server.load("fonts/FiraSans-Bold.ttf"), | ||
// font_size: 30.0, | ||
// color: Color::WHITE, | ||
// }, | ||
// Default::default(), | ||
// ), | ||
// ..Default::default() | ||
// }); | ||
}); | ||
}); | ||
// right vertical fill | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)), | ||
..Default::default() | ||
}, | ||
color: Color::rgb(0.15, 0.15, 0.15), | ||
..Default::default() | ||
}); | ||
// absolute positioning | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(200.0), Val::Px(200.0)), | ||
position_type: PositionType::Absolute, | ||
position: Rect { | ||
left: Val::Px(210.0), | ||
bottom: Val::Px(10.0), | ||
..Default::default() | ||
}, | ||
border: Rect::all(Val::Px(20.0)), | ||
..Default::default() | ||
}, | ||
color: Color::rgb(0.4, 0.4, 1.0), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
..Default::default() | ||
}, | ||
color: Color::rgb(0.8, 0.8, 1.0), | ||
..Default::default() | ||
}); | ||
}); | ||
// render order test: reddest in the back, whitest in the front (flex center) | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
position_type: PositionType::Absolute, | ||
align_items: AlignItems::Center, | ||
justify_content: JustifyContent::Center, | ||
..Default::default() | ||
}, | ||
color: Color::NONE, | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
..Default::default() | ||
}, | ||
color: Color::rgb(1.0, 0.0, 0.0), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
position_type: PositionType::Absolute, | ||
position: Rect { | ||
left: Val::Px(20.0), | ||
bottom: Val::Px(20.0), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
color: Color::rgb(1.0, 0.3, 0.3), | ||
..Default::default() | ||
}); | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
position_type: PositionType::Absolute, | ||
position: Rect { | ||
left: Val::Px(40.0), | ||
bottom: Val::Px(40.0), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
color: Color::rgb(1.0, 0.5, 0.5), | ||
..Default::default() | ||
}); | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
position_type: PositionType::Absolute, | ||
position: Rect { | ||
left: Val::Px(60.0), | ||
bottom: Val::Px(60.0), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
color: Color::rgb(1.0, 0.7, 0.7), | ||
..Default::default() | ||
}); | ||
// alpha test | ||
parent.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
position_type: PositionType::Absolute, | ||
position: Rect { | ||
left: Val::Px(80.0), | ||
bottom: Val::Px(80.0), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
color: Color::rgba(1.0, 0.9, 0.9, 0.4), | ||
..Default::default() | ||
}); | ||
}); | ||
}); | ||
// bevy logo (flex center) | ||
parent | ||
.spawn_bundle(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
position_type: PositionType::Absolute, | ||
justify_content: JustifyContent::Center, | ||
align_items: AlignItems::FlexEnd, | ||
..Default::default() | ||
}, | ||
color: Color::NONE, | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
// bevy logo (image) | ||
parent.spawn_bundle(ImageBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(500.0), Val::Auto), | ||
..Default::default() | ||
}, | ||
texture: Some(asset_server.load("branding/bevy_logo_dark_big.png")), | ||
..Default::default() | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "bevy_ui2" | ||
version = "0.5.0" | ||
edition = "2018" | ||
authors = [ | ||
"Bevy Contributors <bevyengine@gmail.com>", | ||
"Carter Anderson <mcanders1@gmail.com>", | ||
] | ||
description = "A custom ECS-driven UI framework built specifically for Bevy Engine" | ||
homepage = "https://bevyengine.org" | ||
repository = "https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["bevy"] | ||
|
||
[dependencies] | ||
# bevy | ||
bevy_app = { path = "../../crates/bevy_app", version = "0.5.0" } | ||
bevy_asset = { path = "../../crates/bevy_asset", version = "0.5.0" } | ||
bevy_core = { path = "../../crates/bevy_core", version = "0.5.0" } | ||
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.5.0" } | ||
bevy_derive = { path = "../../crates/bevy_derive", version = "0.5.0" } | ||
bevy_ecs = { path = "../../crates/bevy_ecs", version = "0.5.0" } | ||
bevy_input = { path = "../../crates/bevy_input", version = "0.5.0" } | ||
bevy_log = { path = "../../crates/bevy_log", version = "0.5.0" } | ||
bevy_math = { path = "../../crates/bevy_math", version = "0.5.0" } | ||
bevy_reflect = { path = "../../crates/bevy_reflect", version = "0.5.0", features = ["bevy"] } | ||
bevy_render2 = { path = "../bevy_render2", version = "0.5.0" } | ||
#bevy_text = { path = "../../crates/bevy_text", version = "0.5.0" } | ||
bevy_transform = { path = "../../crates/bevy_transform", version = "0.5.0" } | ||
bevy_window = { path = "../../crates/bevy_window", version = "0.5.0" } | ||
bevy_utils = { path = "../../crates/bevy_utils", version = "0.5.0" } | ||
|
||
# other | ||
stretch = "0.3.2" | ||
serde = {version = "1", features = ["derive"]} | ||
smallvec = { version = "1.6", features = ["union", "const_generics"] } | ||
crevice = { path = "../../crates/crevice", version = "0.6.0" } | ||
bytemuck = "1.5" | ||
wgpu = "0.11.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Anchors { | ||
pub left: f32, | ||
pub right: f32, | ||
pub bottom: f32, | ||
pub top: f32, | ||
} | ||
|
||
impl Anchors { | ||
pub const BOTTOM_FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 0.0); | ||
pub const BOTTOM_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.0, 0.0); | ||
pub const BOTTOM_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.0, 0.0); | ||
pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5); | ||
pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0); | ||
pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5); | ||
pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0); | ||
pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5); | ||
pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5); | ||
pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0); | ||
pub const FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 1.0); | ||
pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0); | ||
pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0); | ||
pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0); | ||
pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0); | ||
pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0); | ||
|
||
pub const fn new(left: f32, right: f32, bottom: f32, top: f32) -> Self { | ||
Anchors { | ||
left, | ||
right, | ||
bottom, | ||
top, | ||
} | ||
} | ||
} | ||
|
||
impl Default for Anchors { | ||
fn default() -> Self { | ||
Anchors { | ||
left: 0.0, | ||
right: 0.0, | ||
bottom: 0.0, | ||
top: 0.0, | ||
} | ||
} | ||
} |
Oops, something went wrong.