Skip to content

Commit c5a319e

Browse files
Fix uses of with_style (now with_layout)
1 parent 30164e7 commit c5a319e

File tree

8 files changed

+151
-186
lines changed

8 files changed

+151
-186
lines changed

examples/games/alien_cake_addict.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,21 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
150150
game.bonus.handle = asset_server.load("models/AlienCake/cakeBirthday.glb#Scene0");
151151

152152
// scoreboard
153-
commands.spawn_bundle(
154-
TextBundle::from_section(
153+
commands
154+
.spawn_bundle(TextBundle::from_section(
155155
"Score:",
156156
TextStyle {
157157
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
158158
font_size: 40.0,
159159
color: Color::rgb(0.5, 0.5, 1.0),
160160
},
161-
)
162-
.with_layout(FlexLayout {
163-
position_type: PositionType::Absolute,
164-
position: UiRect {
165-
top: Val::Px(5.0),
166-
left: Val::Px(5.0),
167-
..default()
168-
},
161+
))
162+
.insert(PositionType::Absolute)
163+
.insert(Offset(UiRect {
164+
top: Val::Px(5.0),
165+
left: Val::Px(5.0),
169166
..default()
170-
}),
171-
);
167+
}));
172168
}
173169

174170
// remove all entities that are not a camera
@@ -371,8 +367,8 @@ fn gameover_keyboard(mut state: ResMut<State<GameState>>, keyboard_input: Res<In
371367
fn display_score(mut commands: Commands, asset_server: Res<AssetServer>, game: Res<Game>) {
372368
commands
373369
.spawn_bundle(NodeBundle {
374-
style: Style {
375-
margin: UiRect::all(Val::Auto),
370+
spacing: Spacing::AUTO_MARGIN,
371+
flex_layout: FlexLayout {
376372
justify_content: JustifyContent::Center,
377373
align_items: AlignItems::Center,
378374
..default()

examples/games/breakout.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
216216
.insert(Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED));
217217

218218
// Scoreboard
219-
commands.spawn_bundle(
220-
TextBundle::from_sections([
219+
commands
220+
.spawn_bundle(TextBundle::from_sections([
221221
TextSection::new(
222222
"Score: ",
223223
TextStyle {
@@ -231,17 +231,13 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
231231
font_size: SCOREBOARD_FONT_SIZE,
232232
color: SCORE_COLOR,
233233
}),
234-
])
235-
.with_layout(FlexLayout {
236-
position_type: PositionType::Absolute,
237-
position: UiRect {
238-
top: SCOREBOARD_TEXT_PADDING,
239-
left: SCOREBOARD_TEXT_PADDING,
240-
..default()
241-
},
234+
]))
235+
.insert(PositionType::Absolute)
236+
.insert(Offset(UiRect {
237+
top: SCOREBOARD_TEXT_PADDING,
238+
left: SCOREBOARD_TEXT_PADDING,
242239
..default()
243-
}),
244-
);
240+
}));
245241

246242
// Walls
247243
commands.spawn_bundle(WallBundle::new(WallLocation::Left));

examples/games/game_menu.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,19 @@ mod game {
163163
.insert(OnGameScreen)
164164
.with_children(|parent| {
165165
// Display two lines of text, the second one with the current settings
166-
parent.spawn_bundle(
167-
TextBundle::from_section(
166+
parent
167+
.spawn_bundle(TextBundle::from_section(
168168
"Will be back to the menu shortly...",
169169
TextStyle {
170170
font: font.clone(),
171171
font_size: 80.0,
172172
color: TEXT_COLOR,
173173
},
174-
)
175-
.with_layout(FlexLayout {
176-
margin: UiRect::all(Val::Px(50.0)),
177-
..default()
178-
}),
179-
);
180-
parent.spawn_bundle(
181-
TextBundle::from_sections([
174+
))
175+
.insert(Spacing::margin(UiRect::all(Val::Px(50.0))));
176+
177+
parent
178+
.spawn_bundle(TextBundle::from_sections([
182179
TextSection::new(
183180
format!("quality: {:?}", *display_quality),
184181
TextStyle {
@@ -203,12 +200,8 @@ mod game {
203200
color: Color::GREEN,
204201
},
205202
),
206-
])
207-
.with_layout(FlexLayout {
208-
margin: UiRect::all(Val::Px(50.0)),
209-
..default()
210-
}),
211-
);
203+
]))
204+
.insert(Spacing::margin(UiRect::all(Val::Px(50.0))));
212205
});
213206
// Spawn a 5 seconds timer to trigger going back to the menu
214207
commands.insert_resource(GameTimer(Timer::from_seconds(5.0, false)));

examples/stress_tests/bevymark.rs

+30-33
Original file line numberDiff line numberDiff line change
@@ -96,45 +96,42 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9696

9797
commands.spawn_bundle(Camera2dBundle::default());
9898
commands
99-
.spawn_bundle(
100-
TextBundle::from_sections([
101-
TextSection::new(
102-
"Bird Count: ",
103-
TextStyle {
104-
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
105-
font_size: 40.0,
106-
color: Color::rgb(0.0, 1.0, 0.0),
107-
},
108-
),
109-
TextSection::from_style(TextStyle {
99+
.spawn_bundle(TextBundle::from_sections([
100+
TextSection::new(
101+
"Bird Count: ",
102+
TextStyle {
110103
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
111104
font_size: 40.0,
112-
color: Color::rgb(0.0, 1.0, 1.0),
113-
}),
114-
TextSection::new(
115-
"\nAverage FPS: ",
116-
TextStyle {
117-
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
118-
font_size: 40.0,
119-
color: Color::rgb(0.0, 1.0, 0.0),
120-
},
121-
),
122-
TextSection::from_style(TextStyle {
105+
color: Color::rgb(0.0, 1.0, 0.0),
106+
},
107+
),
108+
TextSection::from_style(TextStyle {
109+
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
110+
font_size: 40.0,
111+
color: Color::rgb(0.0, 1.0, 1.0),
112+
}),
113+
TextSection::new(
114+
"\nAverage FPS: ",
115+
TextStyle {
123116
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
124117
font_size: 40.0,
125-
color: Color::rgb(0.0, 1.0, 1.0),
126-
}),
127-
])
128-
.with_layout(FlexLayout {
129-
position_type: PositionType::Absolute,
130-
position: UiRect {
131-
top: Val::Px(5.0),
132-
left: Val::Px(5.0),
133-
..default()
118+
color: Color::rgb(0.0, 1.0, 0.0),
134119
},
135-
..default()
120+
),
121+
TextSection::from_style(TextStyle {
122+
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
123+
font_size: 40.0,
124+
color: Color::rgb(0.0, 1.0, 1.0),
136125
}),
137-
)
126+
]))
127+
.insert(PositionType::Absolute)
128+
.insert(Offset({
129+
UiRect {
130+
top: Val::Px(5.0),
131+
left: Val::Px(5.0),
132+
..default()
133+
}
134+
}))
138135
.insert(StatsText);
139136

140137
commands.insert_resource(BirdTexture(texture));

examples/ui/text.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
4646
// Set the style of the TextBundle itself.
4747
.with_layout(FlexLayout {
4848
align_self: AlignSelf::FlexEnd,
49-
position_type: PositionType::Absolute,
50-
position: UiRect {
51-
bottom: Val::Px(5.0),
52-
right: Val::Px(15.0),
53-
..default()
54-
},
5549
..default()
5650
}),
5751
)
52+
.insert(PositionType::Absolute)
53+
.insert(Offset(UiRect {
54+
bottom: Val::Px(5.0),
55+
right: Val::Px(15.0),
56+
..default()
57+
}))
5858
.insert(ColorText);
5959
// Text with multiple sections
6060
commands

examples/ui/text_debug.rs

+53-58
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@ struct TextChanges;
2525
fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
2626
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
2727
commands.spawn_bundle(Camera2dBundle::default());
28-
commands.spawn_bundle(
29-
TextBundle::from_section(
30-
"This is\ntext with\nline breaks\nin the top left",
31-
TextStyle {
32-
font: font.clone(),
33-
font_size: 50.0,
34-
color: Color::WHITE,
35-
},
36-
)
37-
.with_layout(FlexLayout {
38-
align_self: AlignSelf::FlexEnd,
39-
position_type: PositionType::Absolute,
40-
position: UiRect {
41-
top: Val::Px(5.0),
42-
left: Val::Px(15.0),
28+
commands
29+
.spawn_bundle(
30+
TextBundle::from_section(
31+
"This is\ntext with\nline breaks\nin the top left",
32+
TextStyle {
33+
font: font.clone(),
34+
font_size: 50.0,
35+
color: Color::WHITE,
36+
},
37+
)
38+
.with_layout(FlexLayout {
39+
align_self: AlignSelf::FlexEnd,
4340
..default()
44-
},
41+
}),
42+
)
43+
.insert(PositionType::Absolute)
44+
.insert(Offset(UiRect {
45+
top: Val::Px(5.0),
46+
left: Val::Px(15.0),
4547
..default()
46-
}),
47-
);
48+
}));
4849
commands.spawn_bundle(TextBundle::from_section(
4950
"This text is very long, has a limited width, is centred, is positioned in the top right and is also coloured pink.",
5051
TextStyle {
@@ -56,19 +57,15 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
5657
.with_text_alignment(TextAlignment::CENTER)
5758
.with_layout(FlexLayout {
5859
align_self: AlignSelf::FlexEnd,
59-
position_type: PositionType::Absolute,
60-
position: UiRect {
61-
top: Val::Px(5.0),
62-
right: Val::Px(15.0),
63-
..default()
64-
},
65-
max_size: Size {
66-
width: Val::Px(400.),
67-
height: Val::Undefined,
68-
},
6960
..default()
70-
})
71-
);
61+
}))
62+
.insert(PositionType::Absolute)
63+
.insert(Offset(UiRect {
64+
top: Val::Px(5.0),
65+
right: Val::Px(15.0),
66+
..default()
67+
}))
68+
.insert(SizeConstraints::max(Val::Px(400.), Val::Undefined));
7269
commands
7370
.spawn_bundle(
7471
TextBundle::from_sections([
@@ -117,40 +114,38 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
117114
])
118115
.with_layout(FlexLayout {
119116
align_self: AlignSelf::FlexEnd,
120-
position_type: PositionType::Absolute,
121-
position: UiRect {
122-
bottom: Val::Px(5.0),
123-
right: Val::Px(15.0),
124-
..default()
125-
},
126117
..default()
127118
}),
128119
)
120+
.insert(PositionType::Absolute)
121+
.insert(Offset(UiRect {
122+
bottom: Val::Px(5.0),
123+
right: Val::Px(15.0),
124+
..default()
125+
}))
129126
.insert(TextChanges);
130-
commands.spawn_bundle(
131-
TextBundle::from_section(
132-
"This\ntext has\nline breaks and also a set width in the bottom left",
133-
TextStyle {
134-
font,
135-
font_size: 50.0,
136-
color: Color::WHITE,
137-
},
138-
)
139-
.with_layout(FlexLayout {
140-
align_self: AlignSelf::FlexEnd,
141-
position_type: PositionType::Absolute,
142-
position: UiRect {
143-
bottom: Val::Px(5.0),
144-
left: Val::Px(15.0),
145-
..default()
146-
},
147-
size: Size {
148-
width: Val::Px(200.0),
127+
commands
128+
.spawn_bundle(
129+
TextBundle::from_section(
130+
"This\ntext has\nline breaks and also a set width in the bottom left",
131+
TextStyle {
132+
font,
133+
font_size: 50.0,
134+
color: Color::WHITE,
135+
},
136+
)
137+
.with_layout(FlexLayout {
138+
align_self: AlignSelf::FlexEnd,
149139
..default()
150-
},
140+
}),
141+
)
142+
.insert(PositionType::Absolute)
143+
.insert(Offset(UiRect {
144+
bottom: Val::Px(5.0),
145+
left: Val::Px(15.0),
151146
..default()
152-
}),
153-
);
147+
}))
148+
.insert(SizeConstraints::suggested(Val::Px(200.), Val::default()));
154149
}
155150

156151
fn change_text_system(

0 commit comments

Comments
 (0)