Skip to content

Rename JustifyText to Justify #19522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_text/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
/// The maximum width and height of text. The text will wrap according to the specified size.
///
/// Characters out of the bounds after wrapping will be truncated. Text is aligned according to the
/// specified [`JustifyText`](crate::text::JustifyText).
/// specified [`Justify`](crate::text::Justify).
///
/// Note: only characters that are completely out of the bounds will be truncated, so this is not a
/// reliable limit if it is necessary to contain the text strictly in the bounds. Currently this
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub use text_access::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Font, JustifyText, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
Font, Justify, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
TextFont, TextLayout, TextSpan,
};
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};

use crate::{
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText,
LineBreak, PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, Justify, LineBreak,
PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
};

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

// Workaround for alignment not working for unbounded text.
// See https://github.com/pop-os/cosmic-text/issues/343
if bounds.width.is_none() && justify != JustifyText::Left {
if bounds.width.is_none() && justify != Justify::Left {
let dimensions = buffer_dimensions(buffer);
// `set_size` causes a re-layout to occur.
buffer.set_size(font_system, Some(dimensions.x), bounds.height);
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ impl Default for ComputedTextBlock {
pub struct TextLayout {
/// The text's internal alignment.
/// Should not affect its position within a container.
pub justify: JustifyText,
pub justify: Justify,
/// How the text should linebreak when running out of the bounds determined by `max_size`.
pub linebreak: LineBreak,
}

impl TextLayout {
/// Makes a new [`TextLayout`].
pub const fn new(justify: JustifyText, linebreak: LineBreak) -> Self {
pub const fn new(justify: Justify, linebreak: LineBreak) -> Self {
Self { justify, linebreak }
}

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

Expand All @@ -143,8 +143,8 @@ impl TextLayout {
Self::default().with_no_wrap()
}

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

impl From<JustifyText> for cosmic_text::Align {
fn from(justify: JustifyText) -> Self {
impl From<Justify> for cosmic_text::Align {
fn from(justify: Justify) -> Self {
match justify {
JustifyText::Left => cosmic_text::Align::Left,
JustifyText::Center => cosmic_text::Align::Center,
JustifyText::Right => cosmic_text::Align::Right,
JustifyText::Justified => cosmic_text::Align::Justified,
Justify::Left => cosmic_text::Align::Left,
Justify::Center => cosmic_text::Align::Center,
Justify::Right => cosmic_text::Align::Right,
Justify::Justified => cosmic_text::Align::Justified,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use bevy_window::{PrimaryWindow, Window};
/// # use bevy_color::Color;
/// # use bevy_color::palettes::basic::BLUE;
/// # use bevy_ecs::world::World;
/// # use bevy_text::{Font, JustifyText, Text2d, TextLayout, TextFont, TextColor, TextSpan};
/// # use bevy_text::{Font, Justify, Text2d, TextLayout, TextFont, TextColor, TextSpan};
/// #
/// # let font_handle: Handle<Font> = Default::default();
/// # let mut world = World::default();
Expand All @@ -73,7 +73,7 @@ use bevy_window::{PrimaryWindow, Window};
/// // With text justification.
/// world.spawn((
/// Text2d::new("hello world\nand bevy!"),
/// TextLayout::new_with_justify(JustifyText::Center)
/// TextLayout::new_with_justify(Justify::Center)
/// ));
///
/// // With spans
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Default for TextNodeFlags {
/// # use bevy_color::Color;
/// # use bevy_color::palettes::basic::BLUE;
/// # use bevy_ecs::world::World;
/// # use bevy_text::{Font, JustifyText, TextLayout, TextFont, TextColor, TextSpan};
/// # use bevy_text::{Font, Justify, TextLayout, TextFont, TextColor, TextSpan};
/// # use bevy_ui::prelude::Text;
/// #
/// # let font_handle: Handle<Font> = Default::default();
Expand All @@ -84,7 +84,7 @@ impl Default for TextNodeFlags {
/// // With text justification.
/// world.spawn((
/// Text::new("hello world\nand bevy!"),
/// TextLayout::new_with_justify(JustifyText::Center)
/// TextLayout::new_with_justify(Justify::Center)
/// ));
///
/// // With spans
Expand Down
4 changes: 2 additions & 2 deletions examples/2d/sprite_scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn setup_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
cmd.with_children(|builder| {
builder.spawn((
Text2d::new(rect.text),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
TextFont::from_font_size(15.),
Transform::from_xyz(0., -0.5 * rect.size.y - 10., 0.),
bevy::sprite::Anchor::TOP_CENTER,
Expand Down Expand Up @@ -275,7 +275,7 @@ fn setup_texture_atlas(
cmd.with_children(|builder| {
builder.spawn((
Text2d::new(sprite_sheet.text),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
TextFont::from_font_size(15.),
Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
bevy::sprite::Anchor::TOP_CENTER,
Expand Down
2 changes: 1 addition & 1 deletion examples/2d/sprite_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn spawn_sprites(
children![(
Text2d::new(label),
text_style,
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
bevy::sprite::Anchor::TOP_CENTER,
)],
Expand Down
10 changes: 5 additions & 5 deletions examples/2d/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
font_size: 50.0,
..default()
};
let text_justification = JustifyText::Center;
let text_justification = Justify::Center;
commands.spawn(Camera2d);
// Demonstrate changing translation
commands.spawn((
Expand Down Expand Up @@ -78,7 +78,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
children![(
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
slightly_smaller_text_font.clone(),
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
TextLayout::new(Justify::Left, LineBreak::WordBoundary),
// Wrap text in the rectangle
TextBounds::from(box_size),
// Ensure the text is drawn on top of the box
Expand All @@ -94,7 +94,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
children![(
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
slightly_smaller_text_font.clone(),
TextLayout::new(JustifyText::Left, LineBreak::AnyCharacter),
TextLayout::new(Justify::Left, LineBreak::AnyCharacter),
// Wrap text in the rectangle
TextBounds::from(other_box_size),
// Ensure the text is drawn on top of the box
Expand All @@ -104,11 +104,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

// Demonstrate font smoothing off
commands.spawn((
Text2d::new("This text has\nFontSmoothing::None\nAnd JustifyText::Center"),
Text2d::new("This text has\nFontSmoothing::None\nAnd Justify::Center"),
slightly_smaller_text_font
.clone()
.with_font_smoothing(FontSmoothing::None),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Transform::from_translation(Vec3::new(-400.0, -250.0, 0.0)),
));

Expand Down
2 changes: 1 addition & 1 deletion examples/2d/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn create_label(
commands.spawn((
Text2d::new(text),
text_style,
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Transform {
translation: Vec3::new(translation.0, translation.1, translation.2),
..default()
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/tonemapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn setup_image_viewer_scene(
..default()
},
TextColor(Color::BLACK),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Node {
align_self: AlignSelf::Center,
margin: UiRect::all(Val::Auto),
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/animated_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn setup(
..default()
},
TextColor(Color::Srgba(Srgba::RED)),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
))
// Mark as an animation target.
.insert(AnimationTarget {
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/animation_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn setup_node_rects(commands: &mut Commands) {
..default()
},
TextColor(ANTIQUE_WHITE.into()),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
))
.id();

Expand Down
2 changes: 1 addition & 1 deletion examples/animation/animation_masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn add_mask_group_control(
} else {
selected_button_text_style.clone()
},
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Node {
flex_grow: 1.0,
margin: UiRect::vertical(Val::Px(3.0)),
Expand Down
2 changes: 1 addition & 1 deletion examples/async_tasks/external_source_external_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
for (per_frame, event) in reader.read().enumerate() {
commands.spawn((
Text2d::new(event.0.to_string()),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0),
));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/one_shot_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn setup_ui(mut commands: Commands) {
commands
.spawn((
Text::default(),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
Node {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
Expand Down
2 changes: 1 addition & 1 deletion examples/math/render_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
children![(
Text::default(),
HeaderText,
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
children![
TextSpan::new("Primitive: "),
TextSpan(format!("{text}", text = PrimitiveSelected::default())),
Expand Down
2 changes: 1 addition & 1 deletion examples/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn setup_scene(
..default()
},
TextColor::BLACK,
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
));
}

Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn setup(mut commands: Commands, args: Res<Args>) {
..Default::default()
};
let text_block = TextLayout {
justify: JustifyText::Left,
justify: Justify::Left,
linebreak: LineBreak::AnyCharacter,
};

Expand Down
6 changes: 3 additions & 3 deletions examples/stress_tests/many_text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Args {
#[argh(switch)]
no_frustum_culling: bool,

/// whether the text should use `JustifyText::Center`.
/// whether the text should use `Justify::Center`.
#[argh(switch)]
center: bool,
}
Expand Down Expand Up @@ -132,9 +132,9 @@ fn setup(mut commands: Commands, font: Res<FontHandle>, args: Res<Args>) {
random_text_font(&mut rng, &args, font.0.clone()),
TextColor(color.into()),
TextLayout::new_with_justify(if args.center {
JustifyText::Center
Justify::Center
} else {
JustifyText::Left
Justify::Left
}),
Transform {
translation,
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/text_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn((
Text2d::default(),
TextLayout {
justify: JustifyText::Center,
justify: Justify::Center,
linebreak: LineBreak::AnyCharacter,
},
TextBounds::default(),
Expand Down
10 changes: 5 additions & 5 deletions examples/testbed/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ mod text {
commands.spawn((Camera2d, DespawnOnExitState(super::Scene::Text)));

for (i, justify) in [
JustifyText::Left,
JustifyText::Right,
JustifyText::Center,
JustifyText::Justified,
Justify::Left,
Justify::Right,
Justify::Center,
Justify::Justified,
]
.into_iter()
.enumerate()
Expand Down Expand Up @@ -196,7 +196,7 @@ mod text {
fn spawn_anchored_text(
commands: &mut Commands,
dest: Vec3,
justify: JustifyText,
justify: Justify,
bounds: Option<TextBounds>,
) {
commands.spawn((
Expand Down
2 changes: 1 addition & 1 deletion examples/testbed/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ mod text_wrap {
for (j, message) in messages.into_iter().enumerate() {
commands.entity(root).with_child((
Text(message.clone()),
TextLayout::new(JustifyText::Left, linebreak),
TextLayout::new(Justify::Left, linebreak),
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.3, 0., 0.)),
));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/time/virtual_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
..default()
},
TextColor(Color::srgb(0.85, 0.85, 0.85)),
TextLayout::new_with_justify(JustifyText::Center),
TextLayout::new_with_justify(Justify::Center),
),
(
Text::default(),
Expand All @@ -111,7 +111,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
..default()
},
TextColor(virtual_color),
TextLayout::new_with_justify(JustifyText::Right),
TextLayout::new_with_justify(Justify::Right),
VirtualTime,
),
],
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/directional_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn setup_ui(
Text::new(button_name),
// And center the text if it flows onto multiple lines
TextLayout {
justify: JustifyText::Center,
justify: Justify::Center,
..default()
},
))
Expand Down
Loading