Skip to content

Commit

Permalink
Upgrade to Bevy 0.15 (#77)
Browse files Browse the repository at this point in the history
* Use bevy from git

* Fix font sizes

* Test: required components

* Update for latest breaking changes

* Update for latest breaking changes

* Fix latest deprecations

* Update for latest breaking changes

* Update for breaking changes from text style split

* Update for latest breaking changes

* Use Bevy release candidate

* This doesn't seem to be needed anymore

* Use bevy 0.15 release

* Fix missing bevy_window dependency

* Clippy

* Cleanup

* Node is necessary so make it a required component
  • Loading branch information
rparrett authored Nov 29, 2024
1 parent b7389a1 commit 82d5f51
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 339 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ exclude = [".github"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.bevy]
version = "0.14"
version = "0.15"
default-features = false
features = ["bevy_ui", "bevy_asset", "bevy_text"]
features = ["bevy_ui", "bevy_asset", "bevy_text", "bevy_window"]

[dev-dependencies.bevy]
version = "0.14"
version = "0.15"
default-features = true

[lints.rust]
Expand Down
40 changes: 18 additions & 22 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use bevy::prelude::*;
use bevy_simple_text_input::{
TextInputBundle, TextInputPlugin, TextInputSubmitEvent, TextInputSystem,
TextInput, TextInputPlugin, TextInputSubmitEvent, TextInputSystem, TextInputTextColor,
TextInputTextFont,
};

const BORDER_COLOR_ACTIVE: Color = Color::srgb(0.75, 0.52, 0.99);
Expand All @@ -19,37 +20,32 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

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(|parent| {
parent.spawn((
NodeBundle {
style: Style {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
border_color: BORDER_COLOR_ACTIVE.into(),
background_color: BACKGROUND_COLOR.into(),
Node {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
TextInputBundle::default().with_text_style(TextStyle {
font_size: 40.,
color: TEXT_COLOR,
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputTextFont(TextFont {
font_size: 34.,
..default()
}),
TextInputTextColor(TextColor(TEXT_COLOR)),
));
});
}
Expand Down
60 changes: 29 additions & 31 deletions examples/focus.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! An example showing a more advanced implementation with focus.
use bevy::prelude::*;
use bevy::{prelude::*, ui::FocusPolicy};
use bevy_simple_text_input::{
TextInputBundle, TextInputInactive, TextInputPlugin, TextInputSystem,
TextInput, TextInputInactive, TextInputPlaceholder, TextInputPlugin, TextInputSystem,
TextInputTextColor, TextInputTextFont,
};

const BORDER_COLOR_ACTIVE: Color = Color::srgb(0.75, 0.52, 0.99);
Expand All @@ -20,18 +21,15 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

commands
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
// Make this container node bundle to be Interactive so that clicking on it removes
Expand All @@ -40,28 +38,28 @@ fn setup(mut commands: Commands) {
))
.with_children(|parent| {
parent.spawn((
NodeBundle {
style: Style {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
border_color: BORDER_COLOR_INACTIVE.into(),
background_color: BACKGROUND_COLOR.into(),
// Prevent clicks on the input from also bubbling down to the container
// behind it
focus_policy: bevy::ui::FocusPolicy::Block,
Node {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
BorderColor(BORDER_COLOR_INACTIVE),
BackgroundColor(BACKGROUND_COLOR),
// Prevent clicks on the input from also bubbling down to the container
// behind it
FocusPolicy::Block,
TextInput,
TextInputTextFont(TextFont {
font_size: 34.,
..default()
}),
TextInputTextColor(TextColor(TEXT_COLOR)),
TextInputPlaceholder {
value: "Click Me".to_string(),
..default()
},
TextInputBundle::default()
.with_text_style(TextStyle {
font_size: 40.,
color: TEXT_COLOR,
..default()
})
.with_placeholder("Click Me", None)
.with_inactive(true),
TextInputInactive(true),
));
});
}
Expand Down
57 changes: 27 additions & 30 deletions examples/password.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! An example showing a masked input for passwords.
use bevy::prelude::*;
use bevy_simple_text_input::{TextInputBundle, TextInputPlugin, TextInputSettings};
use bevy_simple_text_input::{
TextInput, TextInputPlugin, TextInputSettings, TextInputTextColor, TextInputTextFont,
TextInputValue,
};

const BORDER_COLOR_ACTIVE: Color = Color::srgb(0.75, 0.52, 0.99);
const TEXT_COLOR: Color = Color::srgb(0.9, 0.9, 0.9);
Expand All @@ -16,43 +19,37 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

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(|parent| {
parent.spawn((
NodeBundle {
style: Style {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
border_color: BORDER_COLOR_ACTIVE.into(),
background_color: BACKGROUND_COLOR.into(),
Node {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
TextInputBundle::default()
.with_value("password")
.with_text_style(TextStyle {
font_size: 40.,
color: TEXT_COLOR,
..default()
})
.with_settings(TextInputSettings {
mask_character: Some('*'),
retain_on_submit: true,
}),
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputValue("password".to_string()),
TextInputTextFont(TextFont {
font_size: 34.,
..default()
}),
TextInputTextColor(TextColor(TEXT_COLOR)),
TextInputSettings {
mask_character: Some('*'),
retain_on_submit: true,
},
));
});
}
76 changes: 36 additions & 40 deletions examples/value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! An example showing a text input that is updated by a button.
use bevy::prelude::*;
use bevy_simple_text_input::{TextInputBundle, TextInputPlugin, TextInputSettings, TextInputValue};
use bevy_simple_text_input::{
TextInput, TextInputPlugin, TextInputSettings, TextInputTextColor, TextInputTextFont,
TextInputValue,
};

const BORDER_COLOR_ACTIVE: Color = Color::srgb(0.75, 0.52, 0.99);
const BORDER_COLOR_INACTIVE: Color = Color::srgb(0.25, 0.25, 0.25);
Expand All @@ -22,66 +25,59 @@ fn main() {
struct IncValueButton;

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let text_style = TextStyle {
let text_font = TextFont {
font_size: 40.,
color: TEXT_COLOR,
..default()
};
let text_color = TextColor(TEXT_COLOR);

commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(10.),
..default()
},
.spawn(Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(10.),
..default()
})
.with_children(|parent| {
parent.spawn((
NodeBundle {
style: Style {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
border_color: BorderColor(BORDER_COLOR_ACTIVE),
background_color: BACKGROUND_COLOR.into(),
Node {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputTextFont(text_font.clone()),
TextInputTextColor(text_color),
TextInputValue("1".to_string()),
TextInputSettings {
retain_on_submit: true,
..default()
},
TextInputBundle::default()
.with_text_style(text_style.clone())
.with_value("1")
.with_settings(TextInputSettings {
retain_on_submit: true,
..default()
}),
));

parent
.spawn((
ButtonBundle {
style: Style {
width: Val::Px(50.),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
justify_content: JustifyContent::Center,
..default()
},
border_color: BorderColor(BORDER_COLOR_INACTIVE),
background_color: BACKGROUND_COLOR.into(),
Button,
Node {
width: Val::Px(50.),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
justify_content: JustifyContent::Center,
..default()
},
BorderColor(BORDER_COLOR_INACTIVE),
BackgroundColor(BACKGROUND_COLOR),
IncValueButton,
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section("+", text_style.clone()));
parent.spawn((Text::new("+"), text_font, text_color));
});
});
}
Expand Down
Loading

0 comments on commit 82d5f51

Please sign in to comment.