Skip to content

Commit

Permalink
Update for latest breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed Oct 20, 2024
1 parent d2869e3 commit 45ddd1f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 94 deletions.
28 changes: 11 additions & 17 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@ fn setup(mut commands: Commands) {
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()
},
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputTextFont(TextFont {
font_size: 34.,
Expand Down
36 changes: 15 additions & 21 deletions examples/focus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! An example showing a more advanced implementation with focus.
use bevy::prelude::*;
use bevy::{prelude::*, ui::FocusPolicy};
use bevy_simple_text_input::{
TextInput, TextInputInactive, TextInputPlaceholder, TextInputPlugin, TextInputSystem,
TextInputTextColor, TextInputTextFont,
Expand All @@ -25,14 +25,11 @@ fn setup(mut commands: Commands) {

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 @@ -41,20 +38,17 @@ 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.,
Expand Down
28 changes: 11 additions & 17 deletions examples/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,23 @@ fn setup(mut commands: Commands) {
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()
},
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputValue("password".to_string()),
TextInputTextFont(TextFont {
Expand Down
48 changes: 20 additions & 28 deletions examples/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,24 @@ fn setup(mut commands: Commands) {
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),
Expand All @@ -70,18 +64,16 @@ fn setup(mut commands: Commands) {

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| {
Expand Down
19 changes: 8 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,14 @@ fn scroll_with_cursor(
mut inner_text_query: Query<
(
&TextLayoutInfo,
&mut Style,
&Node,
&mut Node,
&ComputedNode,
&Parent,
Option<&TargetCamera>,
),
(With<TextInputInner>, Changed<TextLayoutInfo>),
>,
mut style_query: Query<(&Node, &mut Style), Without<TextInputInner>>,
mut style_query: Query<(&ComputedNode, &mut Node), Without<TextInputInner>>,
camera_query: Query<&Camera>,
window_query: Query<&Window>,
primary_window_query: Query<&Window, With<PrimaryWindow>>,
Expand Down Expand Up @@ -656,7 +656,7 @@ fn create(
} else {
Visibility::Hidden
},
Style {
Node {
position_type: PositionType::Absolute,
..default()
},
Expand All @@ -665,13 +665,10 @@ fn create(

let overflow_container = commands
.spawn((
NodeBundle {
style: Style {
overflow: Overflow::clip(),
justify_content: JustifyContent::FlexEnd,
max_width: Val::Percent(100.),
..default()
},
Node {
overflow: Overflow::clip(),
justify_content: JustifyContent::FlexEnd,
max_width: Val::Percent(100.),
..default()
},
Name::new("TextInputOverflowContainer"),
Expand Down

0 comments on commit 45ddd1f

Please sign in to comment.