Rename BreakLineOn to LineBreak (#15583)

# Objective

- Improve code quality in preparation for
https://github.com/bevyengine/bevy/discussions/15014

## Solution

- Rename BreakLineOn to LineBreak.

## Migration Guide

`BreakLineOn` was renamed to `LineBreak`, and paramters named
`linebreak_behavior` were renamed to `linebreak`.
This commit is contained in:
UkoeHB 2024-10-01 17:30:50 -05:00 committed by GitHub
parent e924df0e1a
commit ead84e0e3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 39 additions and 39 deletions

View File

@ -16,7 +16,7 @@ use bevy_utils::HashMap;
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap}; use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
use crate::{ use crate::{
error::TextError, BreakLineOn, CosmicBuffer, Font, FontAtlasSets, FontSmoothing, JustifyText, error::TextError, CosmicBuffer, Font, FontAtlasSets, FontSmoothing, JustifyText, LineBreak,
PositionedGlyph, TextBounds, TextSection, YAxisOrientation, PositionedGlyph, TextBounds, TextSection, YAxisOrientation,
}; };
@ -73,7 +73,7 @@ impl TextPipeline {
&mut self, &mut self,
fonts: &Assets<Font>, fonts: &Assets<Font>,
sections: &[TextSection], sections: &[TextSection],
linebreak_behavior: BreakLineOn, linebreak: LineBreak,
bounds: TextBounds, bounds: TextBounds,
scale_factor: f64, scale_factor: f64,
buffer: &mut CosmicBuffer, buffer: &mut CosmicBuffer,
@ -144,11 +144,11 @@ impl TextPipeline {
buffer.set_wrap( buffer.set_wrap(
font_system, font_system,
match linebreak_behavior { match linebreak {
BreakLineOn::WordBoundary => Wrap::Word, LineBreak::WordBoundary => Wrap::Word,
BreakLineOn::AnyCharacter => Wrap::Glyph, LineBreak::AnyCharacter => Wrap::Glyph,
BreakLineOn::WordOrCharacter => Wrap::WordOrGlyph, LineBreak::WordOrCharacter => Wrap::WordOrGlyph,
BreakLineOn::NoWrap => Wrap::None, LineBreak::NoWrap => Wrap::None,
}, },
); );
@ -183,7 +183,7 @@ impl TextPipeline {
sections: &[TextSection], sections: &[TextSection],
scale_factor: f64, scale_factor: f64,
text_alignment: JustifyText, text_alignment: JustifyText,
linebreak_behavior: BreakLineOn, linebreak: LineBreak,
font_smoothing: FontSmoothing, font_smoothing: FontSmoothing,
bounds: TextBounds, bounds: TextBounds,
font_atlas_sets: &mut FontAtlasSets, font_atlas_sets: &mut FontAtlasSets,
@ -204,7 +204,7 @@ impl TextPipeline {
self.update_buffer( self.update_buffer(
fonts, fonts,
sections, sections,
linebreak_behavior, linebreak,
bounds, bounds,
scale_factor, scale_factor,
buffer, buffer,
@ -301,7 +301,7 @@ impl TextPipeline {
fonts: &Assets<Font>, fonts: &Assets<Font>,
sections: &[TextSection], sections: &[TextSection],
scale_factor: f64, scale_factor: f64,
linebreak_behavior: BreakLineOn, linebreak: LineBreak,
buffer: &mut CosmicBuffer, buffer: &mut CosmicBuffer,
text_alignment: JustifyText, text_alignment: JustifyText,
font_system: &mut CosmicFontSystem, font_system: &mut CosmicFontSystem,
@ -311,7 +311,7 @@ impl TextPipeline {
self.update_buffer( self.update_buffer(
fonts, fonts,
sections, sections,
linebreak_behavior, linebreak,
MIN_WIDTH_CONTENT_BOUNDS, MIN_WIDTH_CONTENT_BOUNDS,
scale_factor, scale_factor,
buffer, buffer,

View File

@ -35,7 +35,7 @@ pub struct Text {
/// Should not affect its position within a container. /// Should not affect its position within a container.
pub justify: JustifyText, pub justify: JustifyText,
/// How the text should linebreak when running out of the bounds determined by `max_size` /// How the text should linebreak when running out of the bounds determined by `max_size`
pub linebreak_behavior: BreakLineOn, pub linebreak: LineBreak,
/// The antialiasing method to use when rendering text. /// The antialiasing method to use when rendering text.
pub font_smoothing: FontSmoothing, pub font_smoothing: FontSmoothing,
} }
@ -123,7 +123,7 @@ impl Text {
/// Returns this [`Text`] with soft wrapping disabled. /// Returns this [`Text`] with soft wrapping disabled.
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur. /// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
pub const fn with_no_wrap(mut self) -> Self { pub const fn with_no_wrap(mut self) -> Self {
self.linebreak_behavior = BreakLineOn::NoWrap; self.linebreak = LineBreak::NoWrap;
self self
} }
@ -253,7 +253,7 @@ impl Default for TextStyle {
/// Determines how lines will be broken when preventing text from running out of bounds. /// Determines how lines will be broken when preventing text from running out of bounds.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Reflect, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Reflect, Serialize, Deserialize)]
#[reflect(Serialize, Deserialize)] #[reflect(Serialize, Deserialize)]
pub enum BreakLineOn { pub enum LineBreak {
/// Uses the [Unicode Line Breaking Algorithm](https://www.unicode.org/reports/tr14/). /// Uses the [Unicode Line Breaking Algorithm](https://www.unicode.org/reports/tr14/).
/// Lines will be broken up at the nearest suitable word boundary, usually a space. /// Lines will be broken up at the nearest suitable word boundary, usually a space.
/// This behavior suits most cases, as it keeps words intact across linebreaks. /// This behavior suits most cases, as it keeps words intact across linebreaks.

View File

@ -1,6 +1,6 @@
use crate::pipeline::CosmicFontSystem; use crate::pipeline::CosmicFontSystem;
use crate::{ use crate::{
BreakLineOn, CosmicBuffer, Font, FontAtlasSets, PositionedGlyph, SwashCache, Text, TextBounds, CosmicBuffer, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, Text, TextBounds,
TextError, TextLayoutInfo, TextPipeline, YAxisOrientation, TextError, TextLayoutInfo, TextPipeline, YAxisOrientation,
}; };
use bevy_asset::Assets; use bevy_asset::Assets;
@ -176,7 +176,7 @@ pub fn update_text2d_layout(
for (entity, text, bounds, text_layout_info, mut buffer) in &mut text_query { for (entity, text, bounds, text_layout_info, mut buffer) in &mut text_query {
if factor_changed || text.is_changed() || bounds.is_changed() || queue.remove(&entity) { if factor_changed || text.is_changed() || bounds.is_changed() || queue.remove(&entity) {
let text_bounds = TextBounds { let text_bounds = TextBounds {
width: if text.linebreak_behavior == BreakLineOn::NoWrap { width: if text.linebreak == LineBreak::NoWrap {
None None
} else { } else {
bounds.width.map(|width| scale_value(width, scale_factor)) bounds.width.map(|width| scale_value(width, scale_factor))
@ -193,7 +193,7 @@ pub fn update_text2d_layout(
&text.sections, &text.sections,
scale_factor.into(), scale_factor.into(),
text.justify, text.justify,
text.linebreak_behavior, text.linebreak,
text.font_smoothing, text.font_smoothing,
text_bounds, text_bounds,
&mut font_atlas_sets, &mut font_atlas_sets,

View File

@ -15,7 +15,7 @@ use {
crate::widget::TextFlags, crate::widget::TextFlags,
bevy_color::Color, bevy_color::Color,
bevy_text::{ bevy_text::{
BreakLineOn, CosmicBuffer, JustifyText, Text, TextLayoutInfo, TextSection, TextStyle, CosmicBuffer, JustifyText, LineBreak, Text, TextLayoutInfo, TextSection, TextStyle,
}, },
}; };
@ -198,7 +198,7 @@ impl TextBundle {
/// Returns this [`TextBundle`] with soft wrapping disabled. /// Returns this [`TextBundle`] with soft wrapping disabled.
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur. /// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
pub const fn with_no_wrap(mut self) -> Self { pub const fn with_no_wrap(mut self) -> Self {
self.text.linebreak_behavior = BreakLineOn::NoWrap; self.text.linebreak = LineBreak::NoWrap;
self self
} }
} }

View File

@ -16,7 +16,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{camera::Camera, texture::Image}; use bevy_render::{camera::Camera, texture::Image};
use bevy_sprite::TextureAtlasLayout; use bevy_sprite::TextureAtlasLayout;
use bevy_text::{ use bevy_text::{
scale_value, BreakLineOn, CosmicBuffer, CosmicFontSystem, Font, FontAtlasSets, JustifyText, scale_value, CosmicBuffer, CosmicFontSystem, Font, FontAtlasSets, JustifyText, LineBreak,
SwashCache, Text, TextBounds, TextError, TextLayoutInfo, TextMeasureInfo, TextPipeline, SwashCache, Text, TextBounds, TextError, TextLayoutInfo, TextMeasureInfo, TextPipeline,
YAxisOrientation, YAxisOrientation,
}; };
@ -120,13 +120,13 @@ fn create_text_measure(
fonts, fonts,
&text.sections, &text.sections,
scale_factor, scale_factor,
text.linebreak_behavior, text.linebreak,
buffer, buffer,
text_alignment, text_alignment,
font_system, font_system,
) { ) {
Ok(measure) => { Ok(measure) => {
if text.linebreak_behavior == BreakLineOn::NoWrap { if text.linebreak == LineBreak::NoWrap {
content_size.set(NodeMeasure::Fixed(FixedMeasure { size: measure.max })); content_size.set(NodeMeasure::Fixed(FixedMeasure { size: measure.max }));
} else { } else {
content_size.set(NodeMeasure::Text(TextMeasure { info: measure })); content_size.set(NodeMeasure::Text(TextMeasure { info: measure }));
@ -239,7 +239,7 @@ fn queue_text(
) { ) {
// Skip the text node if it is waiting for a new measure func // Skip the text node if it is waiting for a new measure func
if !text_flags.needs_new_measure_func { if !text_flags.needs_new_measure_func {
let physical_node_size = if text.linebreak_behavior == BreakLineOn::NoWrap { let physical_node_size = if text.linebreak == LineBreak::NoWrap {
// With `NoWrap` set, no constraints are placed on the width of the text. // With `NoWrap` set, no constraints are placed on the width of the text.
TextBounds::UNBOUNDED TextBounds::UNBOUNDED
} else { } else {
@ -257,7 +257,7 @@ fn queue_text(
&text.sections, &text.sections,
scale_factor.into(), scale_factor.into(),
text.justify, text.justify,
text.linebreak_behavior, text.linebreak,
text.font_smoothing, text.font_smoothing,
physical_node_size, physical_node_size,
font_atlas_sets, font_atlas_sets,

View File

@ -10,7 +10,7 @@ use bevy::{
math::ops, math::ops,
prelude::*, prelude::*,
sprite::Anchor, sprite::Anchor,
text::{BreakLineOn, FontSmoothing, TextBounds}, text::{FontSmoothing, LineBreak, TextBounds},
}; };
fn main() { fn main() {
@ -96,7 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
slightly_smaller_text_style.clone(), slightly_smaller_text_style.clone(),
)], )],
justify: JustifyText::Left, justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::WordBoundary, linebreak: LineBreak::WordBoundary,
..default() ..default()
}, },
// Wrap text in the rectangle // Wrap text in the rectangle
@ -127,7 +127,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
slightly_smaller_text_style.clone(), slightly_smaller_text_style.clone(),
)], )],
justify: JustifyText::Left, justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::AnyCharacter, linebreak: LineBreak::AnyCharacter,
..default() ..default()
}, },
// Wrap text in the rectangle // Wrap text in the rectangle

View File

@ -9,7 +9,7 @@ use bevy::{
color::palettes::basic::RED, color::palettes::basic::RED,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
text::{BreakLineOn, TextBounds}, text::{LineBreak, TextBounds},
window::{PresentMode, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };
@ -54,7 +54,7 @@ fn setup(mut commands: Commands) {
}, },
}], }],
justify: JustifyText::Left, justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::AnyCharacter, linebreak: LineBreak::AnyCharacter,
..default() ..default()
}; };

View File

@ -6,7 +6,7 @@ use bevy::{
color::palettes::basic::{BLUE, YELLOW}, color::palettes::basic::{BLUE, YELLOW},
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
text::{BreakLineOn, TextBounds}, text::{LineBreak, TextBounds},
window::{PresentMode, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };
@ -65,7 +65,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
text: Text { text: Text {
sections, sections,
justify: JustifyText::Center, justify: JustifyText::Center,
linebreak_behavior: BreakLineOn::AnyCharacter, linebreak: LineBreak::AnyCharacter,
..default() ..default()
}, },
..Default::default() ..Default::default()

View File

@ -1,7 +1,7 @@
//! This example demonstrates text wrapping and use of the `LineBreakOn` property. //! This example demonstrates text wrapping and use of the `LineBreakOn` property.
use argh::FromArgs; use argh::FromArgs;
use bevy::{prelude::*, text::BreakLineOn, window::WindowResolution, winit::WinitSettings}; use bevy::{prelude::*, text::LineBreak, window::WindowResolution, winit::WinitSettings};
#[derive(FromArgs, Resource)] #[derive(FromArgs, Resource)]
/// `text_wrap_debug` demonstrates text wrapping and use of the `LineBreakOn` property /// `text_wrap_debug` demonstrates text wrapping and use of the `LineBreakOn` property
@ -64,11 +64,11 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
}) })
.id(); .id();
for linebreak_behavior in [ for linebreak in [
BreakLineOn::AnyCharacter, LineBreak::AnyCharacter,
BreakLineOn::WordBoundary, LineBreak::WordBoundary,
BreakLineOn::WordOrCharacter, LineBreak::WordOrCharacter,
BreakLineOn::NoWrap, LineBreak::NoWrap,
] { ] {
let row_id = commands let row_id = commands
.spawn(NodeBundle { .spawn(NodeBundle {
@ -112,7 +112,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
let messages = [ let messages = [
format!("JustifyContent::{justification:?}"), format!("JustifyContent::{justification:?}"),
format!("LineBreakOn::{linebreak_behavior:?}"), format!("LineBreakOn::{linebreak:?}"),
"Line 1\nLine 2".to_string(), "Line 1\nLine 2".to_string(),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas auctor, nunc ac faucibus fringilla.".to_string(), "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas auctor, nunc ac faucibus fringilla.".to_string(),
"pneumonoultramicroscopicsilicovolcanoconiosis".to_string() "pneumonoultramicroscopicsilicovolcanoconiosis".to_string()
@ -125,7 +125,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
style: text_style.clone(), style: text_style.clone(),
}], }],
justify: JustifyText::Left, justify: JustifyText::Left,
linebreak_behavior, linebreak,
..default() ..default()
}; };
let text_id = commands let text_id = commands