Skip to content

Commit 901bfd5

Browse files
committed
Renamed 'TextLineBreakBehaviour' to 'BreakLineOn'
Adjusted the documentation to include a link to Unicode Standard Annex #14, Unicode Line Breaking Algorithm.
1 parent 8a32172 commit 901bfd5

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

crates/bevy_text/src/glyph_brush.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use glyph_brush_layout::{
1010
};
1111

1212
use crate::{
13-
error::TextError, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, TextAlignment,
14-
TextLineBreakBehaviour, TextSettings, YAxisOrientation,
13+
error::TextError, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo,
14+
TextAlignment, TextSettings, YAxisOrientation,
1515
};
1616

1717
pub struct GlyphBrush {
@@ -36,7 +36,7 @@ impl GlyphBrush {
3636
sections: &[S],
3737
bounds: Vec2,
3838
text_alignment: TextAlignment,
39-
linebreak_behaviour: TextLineBreakBehaviour,
39+
linebreak_behaviour: BreakLineOn,
4040
) -> Result<Vec<SectionGlyph>, TextError> {
4141
let geom = SectionGeometry {
4242
bounds: (bounds.x, bounds.y),

crates/bevy_text/src/pipeline.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use bevy_utils::HashMap;
1010
use glyph_brush_layout::{FontId, SectionText};
1111

1212
use crate::{
13-
error::TextError, glyph_brush::GlyphBrush, scale_value, Font, FontAtlasSet, FontAtlasWarning,
14-
PositionedGlyph, TextAlignment, TextLineBreakBehaviour, TextSection, TextSettings,
15-
YAxisOrientation,
13+
error::TextError, glyph_brush::GlyphBrush, scale_value, BreakLineOn, Font, FontAtlasSet,
14+
FontAtlasWarning, PositionedGlyph, TextAlignment, TextSection, TextSettings, YAxisOrientation,
1615
};
1716

1817
#[derive(Default, Resource)]
@@ -46,7 +45,7 @@ impl TextPipeline {
4645
sections: &[TextSection],
4746
scale_factor: f64,
4847
text_alignment: TextAlignment,
49-
linebreak_behaviour: TextLineBreakBehaviour,
48+
linebreak_behaviour: BreakLineOn,
5049
bounds: Vec2,
5150
font_atlas_set_storage: &mut Assets<FontAtlasSet>,
5251
texture_atlases: &mut Assets<TextureAtlas>,

crates/bevy_text/src/text.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ pub struct Text {
1515
/// Should not affect its position within a container.
1616
pub alignment: TextAlignment,
1717
/// How the text should linebreak when running out of the bounds determined by max_size
18-
pub linebreak_behaviour: TextLineBreakBehaviour,
18+
pub linebreak_behaviour: BreakLineOn,
1919
}
2020

2121
impl Default for Text {
2222
fn default() -> Self {
2323
Self {
2424
sections: Default::default(),
2525
alignment: TextAlignment::Left,
26-
linebreak_behaviour: TextLineBreakBehaviour::Unicode,
26+
linebreak_behaviour: BreakLineOn::WordBoundary,
2727
}
2828
}
2929
}
@@ -177,24 +177,22 @@ impl Default for TextStyle {
177177
/// Determines how lines will be broken when preventing text from running out of bounds.
178178
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)]
179179
#[reflect(Serialize, Deserialize)]
180-
pub enum TextLineBreakBehaviour {
181-
/// Lines will be broken up at the nearest word boundary, usually at a space.<br/>
182-
/// This behaviour suits most cases, as it keeps words intact. Aims to implement the Unicode line breaking algorithm.
183-
Unicode,
184-
/// Lines will be broken without discrimination at the first character that runs out of bounds.<br/>
185-
/// This is closer to the behaviour one might expect from a terminal.
180+
pub enum BreakLineOn {
181+
/// Uses the [Unicode Line Breaking Algorithm](https://www.unicode.org/reports/tr14/).<br/>
182+
/// Lines will be broken up at the nearest suitable word boundary, usually a space.<br/>
183+
/// This behaviour suits most cases, as it keeps words intact across linebreaks.<br/>
184+
WordBoundary,
185+
/// Lines will be broken without discrimination on any character that would leave bounds.<br/>
186+
/// This is closer to the behaviour one might expect from text in a terminal. <br/>
187+
/// However it may lead to words being broken up across linebreaks<br />
186188
AnyCharacter,
187189
}
188190

189-
impl From<TextLineBreakBehaviour> for glyph_brush_layout::BuiltInLineBreaker {
190-
fn from(val: TextLineBreakBehaviour) -> Self {
191+
impl From<BreakLineOn> for glyph_brush_layout::BuiltInLineBreaker {
192+
fn from(val: BreakLineOn) -> Self {
191193
match val {
192-
TextLineBreakBehaviour::Unicode => {
193-
glyph_brush_layout::BuiltInLineBreaker::UnicodeLineBreaker
194-
}
195-
TextLineBreakBehaviour::AnyCharacter => {
196-
glyph_brush_layout::BuiltInLineBreaker::AnyCharLineBreaker
197-
}
194+
BreakLineOn::WordBoundary => glyph_brush_layout::BuiltInLineBreaker::UnicodeLineBreaker,
195+
BreakLineOn::AnyCharacter => glyph_brush_layout::BuiltInLineBreaker::AnyCharLineBreaker,
198196
}
199197
}
200198
}

examples/2d/text2d.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use bevy::{
99
prelude::*,
10-
text::{Text2dBounds, TextLineBreakBehaviour},
10+
text::{BreakLineOn, Text2dBounds},
1111
};
1212

1313
fn main() {
@@ -90,7 +90,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9090
slightly_smaller_text_style.clone(),
9191
)],
9292
alignment: TextAlignment::Left,
93-
linebreak_behaviour: TextLineBreakBehaviour::Unicode,
93+
linebreak_behaviour: BreakLineOn::WordBoundary,
9494
},
9595
text_2d_bounds: Text2dBounds {
9696
// Wrap text in the rectangle
@@ -122,7 +122,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
122122
slightly_smaller_text_style.clone(),
123123
)],
124124
alignment: TextAlignment::Left,
125-
linebreak_behaviour: TextLineBreakBehaviour::AnyCharacter,
125+
linebreak_behaviour: BreakLineOn::AnyCharacter,
126126
},
127127
text_2d_bounds: Text2dBounds {
128128
// Wrap text in the rectangle

0 commit comments

Comments
 (0)