Skip to content

Commit 950a9de

Browse files
Disable button labels for the many_buttons stress text by default (#20636)
# Objective The `many_buttons` benchmark isn't a good measure of UI performance because it's dominated by the text layout and rendering for the button labels. The button labels should be disabled by default, we have other text specific stress tests. ## Solution 1. Rename the `no_text` commandline parameter to `text`. The buttons are no longer shown by default, to run the example with labels you need to use: ``` cargo run --example many_buttons --release -- --text ``` 2. Add a second button icon image, this is to break up the batches during rendering without text. 3. Spawn every button with an icon. Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 84cb255 commit 950a9de

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

examples/stress_tests/many_buttons.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const FONT_SIZE: f32 = 7.0;
1515
#[derive(FromArgs, Resource)]
1616
/// `many_buttons` general UI benchmark that stress tests layouting, text, interaction and rendering
1717
struct Args {
18-
/// whether to add text to each button
18+
/// whether to add labels to each button
1919
#[argh(switch)]
20-
no_text: bool,
20+
text: bool,
2121

2222
/// whether to add borders to each button
2323
#[argh(switch)]
@@ -27,15 +27,15 @@ struct Args {
2727
#[argh(switch)]
2828
relayout: bool,
2929

30-
/// whether to recompute all text each frame
30+
/// whether to recompute all text each frame (if text enabled)
3131
#[argh(switch)]
3232
recompute_text: bool,
3333

3434
/// how many buttons per row and column of the grid.
3535
#[argh(option, default = "110")]
3636
buttons: usize,
3737

38-
/// give every nth button an image
38+
/// change the button icon every nth button, if `0` no icons are added.
3939
#[argh(option, default = "4")]
4040
image_freq: usize,
4141

@@ -153,8 +153,11 @@ fn button_system(
153153
}
154154

155155
fn setup_flex(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<Args>) {
156-
let image = if 0 < args.image_freq {
157-
Some(asset_server.load("branding/icon.png"))
156+
let images = if 0 < args.image_freq {
157+
Some(vec![
158+
asset_server.load("branding/icon.png"),
159+
asset_server.load("textures/Game Icons/wrench.png"),
160+
])
158161
} else {
159162
None
160163
};
@@ -193,13 +196,12 @@ fn setup_flex(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<
193196
buttons_f,
194197
column,
195198
row,
196-
!args.no_text,
199+
args.text,
197200
border,
198201
border_color,
199-
image
200-
.as_ref()
201-
.filter(|_| (column + row) % args.image_freq == 0)
202-
.cloned(),
202+
images.as_ref().map(|images| {
203+
images[((column + row) / args.image_freq) % images.len()].clone()
204+
}),
203205
);
204206
}
205207
});
@@ -208,8 +210,11 @@ fn setup_flex(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<
208210
}
209211

210212
fn setup_grid(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<Args>) {
211-
let image = if 0 < args.image_freq {
212-
Some(asset_server.load("branding/icon.png"))
213+
let images = if 0 < args.image_freq {
214+
Some(vec![
215+
asset_server.load("branding/icon.png"),
216+
asset_server.load("textures/Game Icons/wrench.png"),
217+
])
213218
} else {
214219
None
215220
};
@@ -246,13 +251,12 @@ fn setup_grid(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<
246251
buttons_f,
247252
column,
248253
row,
249-
!args.no_text,
254+
args.text,
250255
border,
251256
border_color,
252-
image
253-
.as_ref()
254-
.filter(|_| (column + row) % args.image_freq == 0)
255-
.cloned(),
257+
images.as_ref().map(|images| {
258+
images[((column + row) / args.image_freq) % images.len()].clone()
259+
}),
256260
);
257261
}
258262
}
@@ -322,8 +326,11 @@ fn despawn_ui(mut commands: Commands, root_node: Single<Entity, (With<Node>, Wit
322326
}
323327

324328
fn setup_many_cameras(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<Args>) {
325-
let image = if 0 < args.image_freq {
326-
Some(asset_server.load("branding/icon.png"))
329+
let images = if 0 < args.image_freq {
330+
Some(vec![
331+
asset_server.load("branding/icon.png"),
332+
asset_server.load("textures/Game Icons/wrench.png"),
333+
])
327334
} else {
328335
None
329336
};
@@ -381,13 +388,13 @@ fn setup_many_cameras(mut commands: Commands, asset_server: Res<AssetServer>, ar
381388
buttons_f,
382389
column,
383390
row,
384-
!args.no_text,
391+
args.text,
385392
border,
386393
border_color,
387-
image
388-
.as_ref()
389-
.filter(|_| (column + row) % args.image_freq == 0)
390-
.cloned(),
394+
images.as_ref().map(|images| {
395+
images[((column + row) / args.image_freq) % images.len()]
396+
.clone()
397+
}),
391398
);
392399
});
393400
});

0 commit comments

Comments
 (0)