Skip to content

Commit 02fa833

Browse files
Rename JustifyText to Justify (#19522)
# Objective Rename `JustifyText`: * The name `JustifyText` is just ugly. * It's inconsistent since no other `bevy_text` types have a `Text-` suffix, only prefix. * It's inconsistent with the other text layout enum `Linebreak` which doesn't have a prefix or suffix. Fixes #19521. ## Solution Rename `JustifyText` to `Justify`. Without other context, it's natural to assume the name `Justify` refers to text justification. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 437c4d5 commit 02fa833

32 files changed

+75
-67
lines changed

crates/bevy_text/src/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
55
/// The maximum width and height of text. The text will wrap according to the specified size.
66
///
77
/// Characters out of the bounds after wrapping will be truncated. Text is aligned according to the
8-
/// specified [`JustifyText`](crate::text::JustifyText).
8+
/// specified [`Justify`](crate::text::Justify).
99
///
1010
/// Note: only characters that are completely out of the bounds will be truncated, so this is not a
1111
/// reliable limit if it is necessary to contain the text strictly in the bounds. Currently this

crates/bevy_text/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub use text_access::*;
6161
pub mod prelude {
6262
#[doc(hidden)]
6363
pub use crate::{
64-
Font, JustifyText, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
64+
Font, Justify, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
6565
TextFont, TextLayout, TextSpan,
6666
};
6767
}

crates/bevy_text/src/pipeline.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1616
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
1717

1818
use crate::{
19-
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText,
20-
LineBreak, PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
19+
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, Justify, LineBreak,
20+
PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
2121
};
2222

2323
/// A wrapper resource around a [`cosmic_text::FontSystem`]
@@ -88,7 +88,7 @@ impl TextPipeline {
8888
fonts: &Assets<Font>,
8989
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextFont, Color)>,
9090
linebreak: LineBreak,
91-
justify: JustifyText,
91+
justify: Justify,
9292
bounds: TextBounds,
9393
scale_factor: f64,
9494
computed: &mut ComputedTextBlock,
@@ -201,7 +201,7 @@ impl TextPipeline {
201201

202202
// Workaround for alignment not working for unbounded text.
203203
// See https://github.com/pop-os/cosmic-text/issues/343
204-
if bounds.width.is_none() && justify != JustifyText::Left {
204+
if bounds.width.is_none() && justify != Justify::Left {
205205
let dimensions = buffer_dimensions(buffer);
206206
// `set_size` causes a re-layout to occur.
207207
buffer.set_size(font_system, Some(dimensions.x), bounds.height);

crates/bevy_text/src/text.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ impl Default for ComputedTextBlock {
116116
pub struct TextLayout {
117117
/// The text's internal alignment.
118118
/// Should not affect its position within a container.
119-
pub justify: JustifyText,
119+
pub justify: Justify,
120120
/// How the text should linebreak when running out of the bounds determined by `max_size`.
121121
pub linebreak: LineBreak,
122122
}
123123

124124
impl TextLayout {
125125
/// Makes a new [`TextLayout`].
126-
pub const fn new(justify: JustifyText, linebreak: LineBreak) -> Self {
126+
pub const fn new(justify: Justify, linebreak: LineBreak) -> Self {
127127
Self { justify, linebreak }
128128
}
129129

130-
/// Makes a new [`TextLayout`] with the specified [`JustifyText`].
131-
pub fn new_with_justify(justify: JustifyText) -> Self {
130+
/// Makes a new [`TextLayout`] with the specified [`Justify`].
131+
pub fn new_with_justify(justify: Justify) -> Self {
132132
Self::default().with_justify(justify)
133133
}
134134

@@ -143,8 +143,8 @@ impl TextLayout {
143143
Self::default().with_no_wrap()
144144
}
145145

146-
/// Returns this [`TextLayout`] with the specified [`JustifyText`].
147-
pub const fn with_justify(mut self, justify: JustifyText) -> Self {
146+
/// Returns this [`TextLayout`] with the specified [`Justify`].
147+
pub const fn with_justify(mut self, justify: Justify) -> Self {
148148
self.justify = justify;
149149
self
150150
}
@@ -246,7 +246,7 @@ impl From<String> for TextSpan {
246246
/// [`TextBounds`](super::bounds::TextBounds) component with an explicit `width` value.
247247
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)]
248248
#[reflect(Serialize, Deserialize, Clone, PartialEq, Hash)]
249-
pub enum JustifyText {
249+
pub enum Justify {
250250
/// Leftmost character is immediately to the right of the render position.
251251
/// Bounds start from the render position and advance rightwards.
252252
#[default]
@@ -263,13 +263,13 @@ pub enum JustifyText {
263263
Justified,
264264
}
265265

266-
impl From<JustifyText> for cosmic_text::Align {
267-
fn from(justify: JustifyText) -> Self {
266+
impl From<Justify> for cosmic_text::Align {
267+
fn from(justify: Justify) -> Self {
268268
match justify {
269-
JustifyText::Left => cosmic_text::Align::Left,
270-
JustifyText::Center => cosmic_text::Align::Center,
271-
JustifyText::Right => cosmic_text::Align::Right,
272-
JustifyText::Justified => cosmic_text::Align::Justified,
269+
Justify::Left => cosmic_text::Align::Left,
270+
Justify::Center => cosmic_text::Align::Center,
271+
Justify::Right => cosmic_text::Align::Right,
272+
Justify::Justified => cosmic_text::Align::Justified,
273273
}
274274
}
275275
}

crates/bevy_text/src/text2d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use bevy_window::{PrimaryWindow, Window};
5151
/// # use bevy_color::Color;
5252
/// # use bevy_color::palettes::basic::BLUE;
5353
/// # use bevy_ecs::world::World;
54-
/// # use bevy_text::{Font, JustifyText, Text2d, TextLayout, TextFont, TextColor, TextSpan};
54+
/// # use bevy_text::{Font, Justify, Text2d, TextLayout, TextFont, TextColor, TextSpan};
5555
/// #
5656
/// # let font_handle: Handle<Font> = Default::default();
5757
/// # let mut world = World::default();
@@ -73,7 +73,7 @@ use bevy_window::{PrimaryWindow, Window};
7373
/// // With text justification.
7474
/// world.spawn((
7575
/// Text2d::new("hello world\nand bevy!"),
76-
/// TextLayout::new_with_justify(JustifyText::Center)
76+
/// TextLayout::new_with_justify(Justify::Center)
7777
/// ));
7878
///
7979
/// // With spans

crates/bevy_ui/src/widget/text.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Default for TextNodeFlags {
6161
/// # use bevy_color::Color;
6262
/// # use bevy_color::palettes::basic::BLUE;
6363
/// # use bevy_ecs::world::World;
64-
/// # use bevy_text::{Font, JustifyText, TextLayout, TextFont, TextColor, TextSpan};
64+
/// # use bevy_text::{Font, Justify, TextLayout, TextFont, TextColor, TextSpan};
6565
/// # use bevy_ui::prelude::Text;
6666
/// #
6767
/// # let font_handle: Handle<Font> = Default::default();
@@ -84,7 +84,7 @@ impl Default for TextNodeFlags {
8484
/// // With text justification.
8585
/// world.spawn((
8686
/// Text::new("hello world\nand bevy!"),
87-
/// TextLayout::new_with_justify(JustifyText::Center)
87+
/// TextLayout::new_with_justify(Justify::Center)
8888
/// ));
8989
///
9090
/// // With spans

examples/2d/sprite_scale.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn setup_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
129129
cmd.with_children(|builder| {
130130
builder.spawn((
131131
Text2d::new(rect.text),
132-
TextLayout::new_with_justify(JustifyText::Center),
132+
TextLayout::new_with_justify(Justify::Center),
133133
TextFont::from_font_size(15.),
134134
Transform::from_xyz(0., -0.5 * rect.size.y - 10., 0.),
135135
bevy::sprite::Anchor::TOP_CENTER,
@@ -275,7 +275,7 @@ fn setup_texture_atlas(
275275
cmd.with_children(|builder| {
276276
builder.spawn((
277277
Text2d::new(sprite_sheet.text),
278-
TextLayout::new_with_justify(JustifyText::Center),
278+
TextLayout::new_with_justify(Justify::Center),
279279
TextFont::from_font_size(15.),
280280
Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
281281
bevy::sprite::Anchor::TOP_CENTER,

examples/2d/sprite_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn spawn_sprites(
9494
children![(
9595
Text2d::new(label),
9696
text_style,
97-
TextLayout::new_with_justify(JustifyText::Center),
97+
TextLayout::new_with_justify(Justify::Center),
9898
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
9999
bevy::sprite::Anchor::TOP_CENTER,
100100
)],

examples/2d/text2d.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
4040
font_size: 50.0,
4141
..default()
4242
};
43-
let text_justification = JustifyText::Center;
43+
let text_justification = Justify::Center;
4444
commands.spawn(Camera2d);
4545
// Demonstrate changing translation
4646
commands.spawn((
@@ -78,7 +78,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
7878
children![(
7979
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
8080
slightly_smaller_text_font.clone(),
81-
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
81+
TextLayout::new(Justify::Left, LineBreak::WordBoundary),
8282
// Wrap text in the rectangle
8383
TextBounds::from(box_size),
8484
// Ensure the text is drawn on top of the box
@@ -94,7 +94,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9494
children![(
9595
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
9696
slightly_smaller_text_font.clone(),
97-
TextLayout::new(JustifyText::Left, LineBreak::AnyCharacter),
97+
TextLayout::new(Justify::Left, LineBreak::AnyCharacter),
9898
// Wrap text in the rectangle
9999
TextBounds::from(other_box_size),
100100
// Ensure the text is drawn on top of the box
@@ -104,11 +104,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
104104

105105
// Demonstrate font smoothing off
106106
commands.spawn((
107-
Text2d::new("This text has\nFontSmoothing::None\nAnd JustifyText::Center"),
107+
Text2d::new("This text has\nFontSmoothing::None\nAnd Justify::Center"),
108108
slightly_smaller_text_font
109109
.clone()
110110
.with_font_smoothing(FontSmoothing::None),
111-
TextLayout::new_with_justify(JustifyText::Center),
111+
TextLayout::new_with_justify(Justify::Center),
112112
Transform::from_translation(Vec3::new(-400.0, -250.0, 0.0)),
113113
));
114114

examples/2d/texture_atlas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn create_label(
279279
commands.spawn((
280280
Text2d::new(text),
281281
text_style,
282-
TextLayout::new_with_justify(JustifyText::Center),
282+
TextLayout::new_with_justify(Justify::Center),
283283
Transform {
284284
translation: Vec3::new(translation.0, translation.1, translation.2),
285285
..default()

0 commit comments

Comments
 (0)