many-buttons
commandline options for text and layout recomputation (#8418)
# Objective Add commandline options that force the recomputation of text and layout to happen every frame.
This commit is contained in:
parent
fe0ad10b0c
commit
8ed7723823
@ -2,6 +2,12 @@
|
|||||||
//!
|
//!
|
||||||
//! To start the demo without text run
|
//! To start the demo without text run
|
||||||
//! `cargo run --example many_buttons --release no-text`
|
//! `cargo run --example many_buttons --release no-text`
|
||||||
|
//!
|
||||||
|
//| To do a full layout update each frame run
|
||||||
|
//! `cargo run --example many_buttons --release recompute-layout`
|
||||||
|
//!
|
||||||
|
//! To recompute all text each frame run
|
||||||
|
//! `cargo run --example many_buttons --release recompute-text`
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
@ -15,8 +21,9 @@ const FONT_SIZE: f32 = 7.0;
|
|||||||
|
|
||||||
/// This example shows what happens when there is a lot of buttons on screen.
|
/// This example shows what happens when there is a lot of buttons on screen.
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
let mut app = App::new();
|
||||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
|
||||||
|
app.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
primary_window: Some(Window {
|
primary_window: Some(Window {
|
||||||
present_mode: PresentMode::Immediate,
|
present_mode: PresentMode::Immediate,
|
||||||
..default()
|
..default()
|
||||||
@ -27,8 +34,21 @@ fn main() {
|
|||||||
.add_plugin(LogDiagnosticsPlugin::default())
|
.add_plugin(LogDiagnosticsPlugin::default())
|
||||||
.init_resource::<UiFont>()
|
.init_resource::<UiFont>()
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, button_system)
|
.add_systems(Update, button_system);
|
||||||
.run();
|
|
||||||
|
if std::env::args().any(|arg| arg == "recompute-layout") {
|
||||||
|
app.add_systems(Update, |mut ui_scale: ResMut<UiScale>| {
|
||||||
|
ui_scale.set_changed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if std::env::args().any(|arg| arg == "recompute-text") {
|
||||||
|
app.add_systems(Update, |mut text_query: Query<&mut Text>| {
|
||||||
|
text_query.for_each_mut(|mut text| text.set_changed());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -73,7 +93,7 @@ fn setup(mut commands: Commands, font: Res<UiFont>) {
|
|||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|commands| {
|
.with_children(|commands| {
|
||||||
let spawn_text = std::env::args().nth(1).as_deref() != Some("no-text");
|
let spawn_text = std::env::args().all(|arg| arg != "no-text");
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
for j in 0..count {
|
for j in 0..count {
|
||||||
let color = as_rainbow(j % i.max(1)).into();
|
let color = as_rainbow(j % i.max(1)).into();
|
||||||
|
Loading…
Reference in New Issue
Block a user