bevy/examples/stress_tests/text_pipeline.rs

73 lines
2.2 KiB
Rust
Raw Normal View History

//! Text pipeline benchmark.
//!
//! Continuously recomputes a large `Text` component with 100 sections.
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
text::{BreakLineOn, Text2dBounds},
window::{PresentMode, WindowPlugin},
};
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync,
..default()
}),
..default()
}),
FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::default(),
))
.add_systems(Startup, spawn)
.add_systems(Update, update_text_bounds)
.run();
}
fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
warn!(include_str!("warning_string.txt"));
commands.spawn(Camera2dBundle::default());
let sections = (1..=50)
.flat_map(|i| {
[
TextSection {
value: "text".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: (4 + i % 10) as f32,
color: Color::BLUE,
},
},
TextSection {
value: "pipeline".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: (4 + i % 11) as f32,
color: Color::YELLOW,
},
},
]
})
.collect::<Vec<_>>();
commands.spawn(Text2dBundle {
text: Text {
sections,
alignment: TextAlignment::Center,
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,
},
..Default::default()
});
}
// changing the bounds of the text will cause a recomputation
fn update_text_bounds(time: Res<Time>, mut text_bounds_query: Query<&mut Text2dBounds>) {
let width = (1. + time.elapsed_seconds().sin()) * 600.0;
for mut text_bounds in text_bounds_query.iter_mut() {
text_bounds.size.x = width;
}
}