bevy/examples/stress_tests/many_glyphs.rs

92 lines
2.6 KiB
Rust
Raw Normal View History

//! Simple text rendering benchmark.
//!
//! Creates a `Text` with a single `TextSection` containing `100_000` glyphs,
//! and renders it with the UI in a white color and with Text2d in a red color.
//!
//! To recompute all text each frame run
//! `cargo run --example many_glyphs --release recompute-text`
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
text::{BreakLineOn, Text2dBounds},
window::{PresentMode, WindowPlugin, WindowResolution},
};
fn main() {
let mut app = App::new();
app.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync,
resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0),
..default()
}),
..default()
}),
FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::default(),
))
.add_systems(Startup, setup);
if std::env::args().any(|arg| arg == "recompute-text") {
app.add_systems(Update, force_text_recomputation);
}
app.run();
}
fn setup(mut commands: Commands) {
warn!(include_str!("warning_string.txt"));
commands.spawn(Camera2dBundle::default());
let mut text = Text {
sections: vec![TextSection {
value: "0123456789".repeat(10_000),
style: TextStyle {
font_size: 4.,
..default()
},
}],
justify: JustifyText::Left,
Changed spelling linebreak_behaviour to linebreak_behavior (#8285) # Objective In the [`Text`](https://github.com/bevyengine/bevy/blob/3442a13d2cb4b2d77c9f7bf8b6dad25742bd21d7/crates/bevy_text/src/text.rs#L18) struct the field is named: `linebreak_behaviour`, the British spelling of _behavior_. **Update**, also found: - `FileDragAndDrop::HoveredFileCancelled` - `TouchPhase::Cancelled` - `Touches.just_cancelled` The majority of all spelling is in the US but when you have a lot of contributors across the world, sometimes spelling differences can pop up in APIs such as in this case. For consistency, I think it would be worth a while to ensure that the API is persistent. Some examples: `from_reflect.rs` has `DefaultBehavior` TextStyle has `color` and uses the `Color` struct. In `bevy_input/src/Touch.rs` `TouchPhase::Cancelled` and _canceled_ are used interchangeably in the documentation I've found that there is also the same type of discrepancies in the documentation, though this is a low priority but is worth checking. **Update**: I've now checked the documentation (See #8291) ## Solution I've only renamed the inconsistencies that have breaking changes and documentation pertaining to them. The rest of the documentation will be changed via #8291. Do note that the winit API is written with UK spelling, thus this may be a cause for confusion: `winit::event::TouchPhase::Cancelled => TouchPhase::Canceled` `winit::event::WindowEvent::HoveredFileCancelled` -> Related to `FileDragAndDrop::HoveredFileCanceled` But I'm hoping to maybe outline other spelling inconsistencies in the API, and maybe an addition to the contribution guide. --- ## Changelog - `Text` field `linebreak_behaviour` has been renamed to `linebreak_behavior`. - Event `FileDragAndDrop::HoveredFileCancelled` has been renamed to `HoveredFileCanceled` - Function `Touches.just_cancelled` has been renamed to `Touches.just_canceled` - Event `TouchPhase::Cancelled` has been renamed to `TouchPhase::Canceled` ## Migration Guide Update where `linebreak_behaviour` is used to `linebreak_behavior` Updated the event `FileDragAndDrop::HoveredFileCancelled` where used to `HoveredFileCanceled` Update `Touches.just_cancelled` where used as `Touches.just_canceled` The event `TouchPhase::Cancelled` is now called `TouchPhase::Canceled`
2023-04-05 21:25:53 +00:00
linebreak_behavior: BreakLineOn::AnyCharacter,
};
commands
.spawn(NodeBundle {
style: Style {
Have a separate implicit viewport node per root node + make viewport node `Display::Grid` (#9637) # Objective Make `bevy_ui` "root" nodes more intuitive to use/style by: - Removing the implicit flexbox styling (such as stretch alignment) that is applied to them, and replacing it with more intuitive CSS Grid styling (notably with stretch alignment disabled in both axes). - Making root nodes layout independently of each other. Instead of there being a single implicit "viewport" node that all root nodes are children of, there is now an implicit "viewport" node *per root node*. And layout of each tree is computed separately. ## Solution - Remove the global implicit viewport node, and instead create an implicit viewport node for each user-specified root node. - Keep track of both the user-specified root nodes and the implicit viewport nodes in a separate `Vec`. - Use the window's size as the `available_space` parameter to `Taffy.compute_layout` rather than setting it on the implicit viewport node (and set the viewport to `height: 100%; width: 100%` to make this "just work"). --- ## Changelog - Bevy UI now lays out root nodes independently of each other in separate layout contexts. - The implicit viewport node (which contains each user-specified root node) is now `Display::Grid` with `align_items` and `justify_items` both set to `Start`. ## Migration Guide - Bevy UI now lays out root nodes independently of each other in separate layout contexts. If you were relying on your root nodes being able to affect each other's layouts, then you may need to wrap them in a single root node. - The implicit viewport node (which contains each user-specified root node) is now `Display::Grid` with `align_items` and `justify_items` both set to `Start`. You may need to add `height: Val::Percent(100.)` to your root nodes if you were previously relying on being implicitly set.
2023-09-19 15:14:46 +00:00
width: Val::Percent(100.),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
})
.with_children(|commands| {
commands.spawn(TextBundle {
text: text.clone(),
style: Style {
width: Val::Px(1000.),
..Default::default()
},
..Default::default()
});
});
text.sections[0].style.color = Color::RED;
commands.spawn(Text2dBundle {
text,
text_anchor: bevy::sprite::Anchor::Center,
text_2d_bounds: Text2dBounds {
size: Vec2::new(1000., f32::INFINITY),
},
..Default::default()
});
}
fn force_text_recomputation(mut text_query: Query<&mut Text>) {
for mut text in &mut text_query {
text.set_changed();
}
}