Skip to content

Commit

Permalink
Rename BreakLineOn to LineBreak (#15583)
Browse files Browse the repository at this point in the history
# Objective

- Improve code quality in preparation for
#15014

## Solution

- Rename BreakLineOn to LineBreak.

## Migration Guide

`BreakLineOn` was renamed to `LineBreak`, and paramters named
`linebreak_behavior` were renamed to `linebreak`.
  • Loading branch information
UkoeHB authored Oct 1, 2024
1 parent e924df0 commit ead84e0
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy_utils::HashMap;
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};

use crate::{
error::TextError, BreakLineOn, CosmicBuffer, Font, FontAtlasSets, FontSmoothing, JustifyText,
error::TextError, CosmicBuffer, Font, FontAtlasSets, FontSmoothing, JustifyText, LineBreak,
PositionedGlyph, TextBounds, TextSection, YAxisOrientation,
};

Expand Down Expand Up @@ -73,7 +73,7 @@ impl TextPipeline {
&mut self,
fonts: &Assets<Font>,
sections: &[TextSection],
linebreak_behavior: BreakLineOn,
linebreak: LineBreak,
bounds: TextBounds,
scale_factor: f64,
buffer: &mut CosmicBuffer,
Expand Down Expand Up @@ -144,11 +144,11 @@ impl TextPipeline {

buffer.set_wrap(
font_system,
match linebreak_behavior {
BreakLineOn::WordBoundary => Wrap::Word,
BreakLineOn::AnyCharacter => Wrap::Glyph,
BreakLineOn::WordOrCharacter => Wrap::WordOrGlyph,
BreakLineOn::NoWrap => Wrap::None,
match linebreak {
LineBreak::WordBoundary => Wrap::Word,
LineBreak::AnyCharacter => Wrap::Glyph,
LineBreak::WordOrCharacter => Wrap::WordOrGlyph,
LineBreak::NoWrap => Wrap::None,
},
);

Expand Down Expand Up @@ -183,7 +183,7 @@ impl TextPipeline {
sections: &[TextSection],
scale_factor: f64,
text_alignment: JustifyText,
linebreak_behavior: BreakLineOn,
linebreak: LineBreak,
font_smoothing: FontSmoothing,
bounds: TextBounds,
font_atlas_sets: &mut FontAtlasSets,
Expand All @@ -204,7 +204,7 @@ impl TextPipeline {
self.update_buffer(
fonts,
sections,
linebreak_behavior,
linebreak,
bounds,
scale_factor,
buffer,
Expand Down Expand Up @@ -301,7 +301,7 @@ impl TextPipeline {
fonts: &Assets<Font>,
sections: &[TextSection],
scale_factor: f64,
linebreak_behavior: BreakLineOn,
linebreak: LineBreak,
buffer: &mut CosmicBuffer,
text_alignment: JustifyText,
font_system: &mut CosmicFontSystem,
Expand All @@ -311,7 +311,7 @@ impl TextPipeline {
self.update_buffer(
fonts,
sections,
linebreak_behavior,
linebreak,
MIN_WIDTH_CONTENT_BOUNDS,
scale_factor,
buffer,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Text {
/// Should not affect its position within a container.
pub justify: JustifyText,
/// 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.
pub font_smoothing: FontSmoothing,
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Text {
/// Returns this [`Text`] with soft wrapping disabled.
/// 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 {
self.linebreak_behavior = BreakLineOn::NoWrap;
self.linebreak = LineBreak::NoWrap;
self
}

Expand Down Expand Up @@ -253,7 +253,7 @@ impl Default for TextStyle {
/// 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)]
#[reflect(Serialize, Deserialize)]
pub enum BreakLineOn {
pub enum LineBreak {
/// 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.
/// This behavior suits most cases, as it keeps words intact across linebreaks.
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::pipeline::CosmicFontSystem;
use crate::{
BreakLineOn, CosmicBuffer, Font, FontAtlasSets, PositionedGlyph, SwashCache, Text, TextBounds,
CosmicBuffer, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, Text, TextBounds,
TextError, TextLayoutInfo, TextPipeline, YAxisOrientation,
};
use bevy_asset::Assets;
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn update_text2d_layout(
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) {
let text_bounds = TextBounds {
width: if text.linebreak_behavior == BreakLineOn::NoWrap {
width: if text.linebreak == LineBreak::NoWrap {
None
} else {
bounds.width.map(|width| scale_value(width, scale_factor))
Expand All @@ -193,7 +193,7 @@ pub fn update_text2d_layout(
&text.sections,
scale_factor.into(),
text.justify,
text.linebreak_behavior,
text.linebreak,
text.font_smoothing,
text_bounds,
&mut font_atlas_sets,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/node_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
crate::widget::TextFlags,
bevy_color::Color,
bevy_text::{
BreakLineOn, CosmicBuffer, JustifyText, Text, TextLayoutInfo, TextSection, TextStyle,
CosmicBuffer, JustifyText, LineBreak, Text, TextLayoutInfo, TextSection, TextStyle,
},
};

Expand Down Expand Up @@ -198,7 +198,7 @@ impl TextBundle {
/// Returns this [`TextBundle`] with soft wrapping disabled.
/// 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 {
self.text.linebreak_behavior = BreakLineOn::NoWrap;
self.text.linebreak = LineBreak::NoWrap;
self
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{camera::Camera, texture::Image};
use bevy_sprite::TextureAtlasLayout;
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,
YAxisOrientation,
};
Expand Down Expand Up @@ -120,13 +120,13 @@ fn create_text_measure(
fonts,
&text.sections,
scale_factor,
text.linebreak_behavior,
text.linebreak,
buffer,
text_alignment,
font_system,
) {
Ok(measure) => {
if text.linebreak_behavior == BreakLineOn::NoWrap {
if text.linebreak == LineBreak::NoWrap {
content_size.set(NodeMeasure::Fixed(FixedMeasure { size: measure.max }));
} else {
content_size.set(NodeMeasure::Text(TextMeasure { info: measure }));
Expand Down Expand Up @@ -239,7 +239,7 @@ fn queue_text(
) {
// Skip the text node if it is waiting for a 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.
TextBounds::UNBOUNDED
} else {
Expand All @@ -257,7 +257,7 @@ fn queue_text(
&text.sections,
scale_factor.into(),
text.justify,
text.linebreak_behavior,
text.linebreak,
text.font_smoothing,
physical_node_size,
font_atlas_sets,
Expand Down
6 changes: 3 additions & 3 deletions examples/2d/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevy::{
math::ops,
prelude::*,
sprite::Anchor,
text::{BreakLineOn, FontSmoothing, TextBounds},
text::{FontSmoothing, LineBreak, TextBounds},
};

fn main() {
Expand Down Expand Up @@ -96,7 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
slightly_smaller_text_style.clone(),
)],
justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::WordBoundary,
linebreak: LineBreak::WordBoundary,
..default()
},
// Wrap text in the rectangle
Expand Down Expand Up @@ -127,7 +127,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
slightly_smaller_text_style.clone(),
)],
justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::AnyCharacter,
linebreak: LineBreak::AnyCharacter,
..default()
},
// Wrap text in the rectangle
Expand Down
4 changes: 2 additions & 2 deletions examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy::{
color::palettes::basic::RED,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
text::{BreakLineOn, TextBounds},
text::{LineBreak, TextBounds},
window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings},
};
Expand Down Expand Up @@ -54,7 +54,7 @@ fn setup(mut commands: Commands) {
},
}],
justify: JustifyText::Left,
linebreak_behavior: BreakLineOn::AnyCharacter,
linebreak: LineBreak::AnyCharacter,
..default()
};

Expand Down
4 changes: 2 additions & 2 deletions examples/stress_tests/text_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::{
color::palettes::basic::{BLUE, YELLOW},
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
text::{BreakLineOn, TextBounds},
text::{LineBreak, TextBounds},
window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings},
};
Expand Down Expand Up @@ -65,7 +65,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
text: Text {
sections,
justify: JustifyText::Center,
linebreak_behavior: BreakLineOn::AnyCharacter,
linebreak: LineBreak::AnyCharacter,
..default()
},
..Default::default()
Expand Down
16 changes: 8 additions & 8 deletions examples/ui/text_wrap_debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This example demonstrates text wrapping and use of the `LineBreakOn` property.

use argh::FromArgs;
use bevy::{prelude::*, text::BreakLineOn, window::WindowResolution, winit::WinitSettings};
use bevy::{prelude::*, text::LineBreak, window::WindowResolution, winit::WinitSettings};

#[derive(FromArgs, Resource)]
/// `text_wrap_debug` demonstrates text wrapping and use of the `LineBreakOn` property
Expand Down Expand Up @@ -64,11 +64,11 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
})
.id();

for linebreak_behavior in [
BreakLineOn::AnyCharacter,
BreakLineOn::WordBoundary,
BreakLineOn::WordOrCharacter,
BreakLineOn::NoWrap,
for linebreak in [
LineBreak::AnyCharacter,
LineBreak::WordBoundary,
LineBreak::WordOrCharacter,
LineBreak::NoWrap,
] {
let row_id = commands
.spawn(NodeBundle {
Expand Down Expand Up @@ -112,7 +112,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {

let messages = [
format!("JustifyContent::{justification:?}"),
format!("LineBreakOn::{linebreak_behavior:?}"),
format!("LineBreakOn::{linebreak:?}"),
"Line 1\nLine 2".to_string(),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas auctor, nunc ac faucibus fringilla.".to_string(),
"pneumonoultramicroscopicsilicovolcanoconiosis".to_string()
Expand All @@ -125,7 +125,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
style: text_style.clone(),
}],
justify: JustifyText::Left,
linebreak_behavior,
linebreak,
..default()
};
let text_id = commands
Expand Down

0 comments on commit ead84e0

Please sign in to comment.