diff --git a/Cargo.toml b/Cargo.toml index e8fd058..10407ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_round_ui" -version = "2.0.0" +version = "4.0.0" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Robert Dodd"] @@ -23,4 +23,4 @@ round_rect = [] superellipse = [] [dependencies] -bevy = "0.14" +bevy = "0.15" diff --git a/README.md b/README.md index 478916c..d1acb17 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ allows you to toggle between the superellipse and round-rect materials to easily | `bevy_round_ui` | `bevy` | |:----------------|:-------| +| `4.x` | `0.15` | | `1.x` - `2.x` | `0.13` | | `0.2` | `0.13` | | `0.1` | `0.12` | diff --git a/examples/autosize.rs b/examples/autosize.rs index 471c504..563abda 100644 --- a/examples/autosize.rs +++ b/examples/autosize.rs @@ -13,29 +13,20 @@ fn main() { fn setup(mut commands: Commands, mut materials: ResMut>) { // Camera so we can see UI - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d); // Spawn two nested panels with flexible sizes in the middle of the window commands - .spawn(NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - ..default() - }, + .spawn((Node { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, ..default() - }) + },)) .with_children(|p| { - p.spawn(MaterialNodeBundle { - material: materials.add(RoundRectUiMaterial { - background_color: css::PINK.into(), - border_color: LinearRgba::WHITE, - border_radius: RoundUiBorder::all(20.).into(), - offset: RoundUiOffset::all(6.).into(), - }), - style: Style { + p.spawn(( + Node { width: Val::Percent(50.), height: Val::Percent(50.), align_items: AlignItems::Center, @@ -44,17 +35,17 @@ fn setup(mut commands: Commands, mut materials: ResMut>, ) { // Camera so we can see UI - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d); // Define a material for the panel. // This material looks like it has a border, because we applied an equal offset to all sides. @@ -94,24 +97,22 @@ fn setup( border_color: Srgba::hex(PANEL_BORDER_COLOR).unwrap().into(), border_radius: RoundUiBorder::all(20.0).into(), border_thickness: 6.0, + ..default() }); // Spawn the screen layout, containing a centered panel with menu items commands - .spawn(NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - ..default() - }, + .spawn((Node { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, ..default() - }) + },)) .with_children(|p| { - p.spawn(MaterialNodeBundle { - material: panel_material, - style: Style { + p.spawn(( + MaterialNode(panel_material), + Node { width: Val::Px(PANEL_WIDTH), padding: UiRect::axes(Val::Px(40.), Val::Px(60.)), flex_direction: FlexDirection::Column, @@ -119,29 +120,25 @@ fn setup( justify_content: JustifyContent::Center, ..default() }, - ..default() - }) + )) .with_children(|p| { // Spawn the title - p.spawn(NodeBundle { - style: Style { - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - margin: UiRect::bottom(Val::Px(40.)), - ..default() - }, + p.spawn((Node { + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + margin: UiRect::bottom(Val::Px(40.)), ..default() - }) - .with_children(|p| { - p.spawn(TextBundle::from_section( - "MENU", - TextStyle { - color: Color::WHITE, - font_size: 40., - ..default() - }, - )); - }); + },)) + .with_children(|p| { + p.spawn(( + Text::new("MENU"), + TextFont { + font_size: 40., + ..default() + }, + TextColor::WHITE, + )); + }); // Spawn the buttons spawn_button(p, &button_style, "Play", ButtonAction::Play); @@ -161,29 +158,26 @@ fn spawn_button( parent .spawn(( RoundButton, - MaterialNodeBundle { - material: button_style.default_material.clone(), - style: Style { - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - width: Val::Percent(100.), - height: Val::Px(BUTTON_HEIGHT), - margin: UiRect::top(Val::Px(10.)), - ..default() - }, + Node { + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + width: Val::Percent(100.), + height: Val::Px(BUTTON_HEIGHT), + margin: UiRect::top(Val::Px(10.)), ..default() }, + MaterialNode(button_style.default_material.clone()), extras, Interaction::default(), )) .with_children(|p| { - p.spawn(TextBundle::from_section( - text, - TextStyle { - color: Color::WHITE, + p.spawn(( + Text::new(text), + TextFont { font_size: 20., ..default() }, + TextColor::WHITE, )); }) .id() @@ -193,7 +187,11 @@ fn spawn_button( #[allow(clippy::type_complexity)] fn handle_button_interactions( mut interaction_query: Query< - (&Interaction, &mut Handle, &mut Style), + ( + &Interaction, + &mut MaterialNode, + &mut Node, + ), (Changed, With), >, button_style: Res, @@ -213,7 +211,7 @@ fn handle_button_interactions( button_style.default_padding, ), }; - *material = material_handle; + **material = material_handle; style.padding = padding; } } diff --git a/examples/circle.rs b/examples/circle.rs index 660d557..a32788d 100644 --- a/examples/circle.rs +++ b/examples/circle.rs @@ -20,7 +20,7 @@ const CIRCLE_BORDER_COLOR: &str = "#A53A3D"; fn setup(mut commands: Commands, mut materials: ResMut>) { // Camera so we can see UI - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d); // Add the material asset. // NOTE: To make a circle, the width, height and border radius should be equal @@ -29,29 +29,26 @@ fn setup(mut commands: Commands, mut materials: ResMut>, ) { // Camera so we can see UI - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d); let border_radius: Vec4 = RoundUiBorder::all(PANEL_WIDTH / 4.).into(); let background_color: LinearRgba = Srgba::hex("#F76161").unwrap().into(); @@ -44,6 +44,7 @@ fn setup( border_color, border_radius, border_thickness: BORDER_THICKNESS, + ..default() }); // Add the round rect material let panel_material_round_rect = old_materials.add(RoundRectUiMaterial { @@ -51,17 +52,15 @@ fn setup( border_color, border_radius, offset: RoundUiOffset::all(BORDER_THICKNESS / 2.).into(), + ..default() }); // Spawn help text commands - .spawn(NodeBundle { - style: Style { - flex_direction: FlexDirection::Column, - ..default() - }, + .spawn((Node { + flex_direction: FlexDirection::Column, ..default() - }) + },)) .with_children(|p| { help_text(p, "Toggle Material: ENTER"); help_text(p, "Toggle Height: SPACE"); @@ -70,67 +69,55 @@ fn setup( // Spawn the material in the middle of the screen commands - .spawn(NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - ..default() - }, + .spawn((Node { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, ..default() - }) + },)) .with_children(|p| { // Spawn a wrapper around the material node with a blue border p.spawn(( PanelBorder(true), - NodeBundle { - style: Style { - border: UiRect::all(Val::Px(1.)), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - ..default() - }, - border_color: css::BLUE.into(), + Node { + border: UiRect::all(Val::Px(1.)), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, ..default() }, + BorderColor(css::BLUE.into()), )) .with_children(|p| { // Spawn a superellipse material, displayed by default p.spawn(( PanelSize::Short, - MaterialNodeBundle { - material: panel_material_superellipse, - style: Style { - width: Val::Px(PANEL_WIDTH), - height: Val::Px(PANEL_HEIGHT), - ..default() - }, + Node { + width: Val::Px(PANEL_WIDTH), + height: Val::Px(PANEL_HEIGHT), ..default() }, + MaterialNode(panel_material_superellipse), )); // Spawn a round rect material, hidden by default p.spawn(( PanelSize::Short, - MaterialNodeBundle { - material: panel_material_round_rect, - style: Style { - width: Val::Px(PANEL_WIDTH), - height: Val::Px(PANEL_HEIGHT), - display: Display::None, - ..default() - }, + Node { + width: Val::Px(PANEL_WIDTH), + height: Val::Px(PANEL_HEIGHT), + display: Display::None, ..default() }, + MaterialNode(panel_material_round_rect), )); }); }); } fn help_text(p: &mut ChildBuilder, val: impl Into) { - p.spawn(TextBundle::from_section( - val, - TextStyle { + p.spawn(( + Text::new(val), + TextFont { font_size: 24., ..default() }, @@ -139,8 +126,8 @@ fn help_text(p: &mut ChildBuilder, val: impl Into) { fn handle_keys( keys: Res>, - mut query: Query<(&mut PanelSize, &mut Style)>, - mut border_query: Query<(&mut PanelBorder, &mut Style), Without>, + mut query: Query<(&mut PanelSize, &mut Node)>, + mut border_query: Query<(&mut PanelBorder, &mut Node), Without>, ) { // Change height when "Space" is pressed if keys.just_pressed(KeyCode::Space) { diff --git a/examples/shapes.rs b/examples/shapes.rs index 02130f4..6456a6a 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -17,7 +17,7 @@ const SPACER_SIZE: f32 = 20.; fn setup(mut commands: Commands, mut materials: ResMut>) { // Camera so we can see UI - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d); let rect_materials = [ // Round rect without offset @@ -32,6 +32,7 @@ fn setup(mut commands: Commands, mut materials: ResMut>, time: Res