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 <alice.i.cecile@gmail.com>
This commit is contained in:
parent
437c4d5b25
commit
02fa833be1
@ -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.
|
/// 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
|
/// 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
|
/// 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
|
/// reliable limit if it is necessary to contain the text strictly in the bounds. Currently this
|
||||||
|
@ -61,7 +61,7 @@ pub use text_access::*;
|
|||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
Font, JustifyText, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
|
Font, Justify, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
|
||||||
TextFont, TextLayout, TextSpan,
|
TextFont, TextLayout, TextSpan,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
|||||||
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
|
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText,
|
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, Justify, LineBreak,
|
||||||
LineBreak, PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
|
PositionedGlyph, TextBounds, TextEntity, TextFont, TextLayout,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A wrapper resource around a [`cosmic_text::FontSystem`]
|
/// A wrapper resource around a [`cosmic_text::FontSystem`]
|
||||||
@ -88,7 +88,7 @@ impl TextPipeline {
|
|||||||
fonts: &Assets<Font>,
|
fonts: &Assets<Font>,
|
||||||
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextFont, Color)>,
|
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextFont, Color)>,
|
||||||
linebreak: LineBreak,
|
linebreak: LineBreak,
|
||||||
justify: JustifyText,
|
justify: Justify,
|
||||||
bounds: TextBounds,
|
bounds: TextBounds,
|
||||||
scale_factor: f64,
|
scale_factor: f64,
|
||||||
computed: &mut ComputedTextBlock,
|
computed: &mut ComputedTextBlock,
|
||||||
@ -201,7 +201,7 @@ impl TextPipeline {
|
|||||||
|
|
||||||
// Workaround for alignment not working for unbounded text.
|
// Workaround for alignment not working for unbounded text.
|
||||||
// See https://github.com/pop-os/cosmic-text/issues/343
|
// 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);
|
let dimensions = buffer_dimensions(buffer);
|
||||||
// `set_size` causes a re-layout to occur.
|
// `set_size` causes a re-layout to occur.
|
||||||
buffer.set_size(font_system, Some(dimensions.x), bounds.height);
|
buffer.set_size(font_system, Some(dimensions.x), bounds.height);
|
||||||
|
@ -116,19 +116,19 @@ impl Default for ComputedTextBlock {
|
|||||||
pub struct TextLayout {
|
pub struct TextLayout {
|
||||||
/// The text's internal alignment.
|
/// The text's internal alignment.
|
||||||
/// Should not affect its position within a container.
|
/// 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`.
|
/// How the text should linebreak when running out of the bounds determined by `max_size`.
|
||||||
pub linebreak: LineBreak,
|
pub linebreak: LineBreak,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextLayout {
|
impl TextLayout {
|
||||||
/// Makes a new [`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 }
|
Self { justify, linebreak }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a new [`TextLayout`] with the specified [`JustifyText`].
|
/// Makes a new [`TextLayout`] with the specified [`Justify`].
|
||||||
pub fn new_with_justify(justify: JustifyText) -> Self {
|
pub fn new_with_justify(justify: Justify) -> Self {
|
||||||
Self::default().with_justify(justify)
|
Self::default().with_justify(justify)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ impl TextLayout {
|
|||||||
Self::default().with_no_wrap()
|
Self::default().with_no_wrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns this [`TextLayout`] with the specified [`JustifyText`].
|
/// Returns this [`TextLayout`] with the specified [`Justify`].
|
||||||
pub const fn with_justify(mut self, justify: JustifyText) -> Self {
|
pub const fn with_justify(mut self, justify: Justify) -> Self {
|
||||||
self.justify = justify;
|
self.justify = justify;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ impl From<String> for TextSpan {
|
|||||||
/// [`TextBounds`](super::bounds::TextBounds) component with an explicit `width` value.
|
/// [`TextBounds`](super::bounds::TextBounds) component with an explicit `width` value.
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)]
|
||||||
#[reflect(Serialize, Deserialize, Clone, PartialEq, Hash)]
|
#[reflect(Serialize, Deserialize, Clone, PartialEq, Hash)]
|
||||||
pub enum JustifyText {
|
pub enum Justify {
|
||||||
/// Leftmost character is immediately to the right of the render position.
|
/// Leftmost character is immediately to the right of the render position.
|
||||||
/// Bounds start from the render position and advance rightwards.
|
/// Bounds start from the render position and advance rightwards.
|
||||||
#[default]
|
#[default]
|
||||||
@ -263,13 +263,13 @@ pub enum JustifyText {
|
|||||||
Justified,
|
Justified,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<JustifyText> for cosmic_text::Align {
|
impl From<Justify> for cosmic_text::Align {
|
||||||
fn from(justify: JustifyText) -> Self {
|
fn from(justify: Justify) -> Self {
|
||||||
match justify {
|
match justify {
|
||||||
JustifyText::Left => cosmic_text::Align::Left,
|
Justify::Left => cosmic_text::Align::Left,
|
||||||
JustifyText::Center => cosmic_text::Align::Center,
|
Justify::Center => cosmic_text::Align::Center,
|
||||||
JustifyText::Right => cosmic_text::Align::Right,
|
Justify::Right => cosmic_text::Align::Right,
|
||||||
JustifyText::Justified => cosmic_text::Align::Justified,
|
Justify::Justified => cosmic_text::Align::Justified,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ use bevy_window::{PrimaryWindow, Window};
|
|||||||
/// # use bevy_color::Color;
|
/// # use bevy_color::Color;
|
||||||
/// # use bevy_color::palettes::basic::BLUE;
|
/// # use bevy_color::palettes::basic::BLUE;
|
||||||
/// # use bevy_ecs::world::World;
|
/// # 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 font_handle: Handle<Font> = Default::default();
|
||||||
/// # let mut world = World::default();
|
/// # let mut world = World::default();
|
||||||
@ -73,7 +73,7 @@ use bevy_window::{PrimaryWindow, Window};
|
|||||||
/// // With text justification.
|
/// // With text justification.
|
||||||
/// world.spawn((
|
/// world.spawn((
|
||||||
/// Text2d::new("hello world\nand bevy!"),
|
/// Text2d::new("hello world\nand bevy!"),
|
||||||
/// TextLayout::new_with_justify(JustifyText::Center)
|
/// TextLayout::new_with_justify(Justify::Center)
|
||||||
/// ));
|
/// ));
|
||||||
///
|
///
|
||||||
/// // With spans
|
/// // With spans
|
||||||
|
@ -61,7 +61,7 @@ impl Default for TextNodeFlags {
|
|||||||
/// # use bevy_color::Color;
|
/// # use bevy_color::Color;
|
||||||
/// # use bevy_color::palettes::basic::BLUE;
|
/// # use bevy_color::palettes::basic::BLUE;
|
||||||
/// # use bevy_ecs::world::World;
|
/// # 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;
|
/// # use bevy_ui::prelude::Text;
|
||||||
/// #
|
/// #
|
||||||
/// # let font_handle: Handle<Font> = Default::default();
|
/// # let font_handle: Handle<Font> = Default::default();
|
||||||
@ -84,7 +84,7 @@ impl Default for TextNodeFlags {
|
|||||||
/// // With text justification.
|
/// // With text justification.
|
||||||
/// world.spawn((
|
/// world.spawn((
|
||||||
/// Text::new("hello world\nand bevy!"),
|
/// Text::new("hello world\nand bevy!"),
|
||||||
/// TextLayout::new_with_justify(JustifyText::Center)
|
/// TextLayout::new_with_justify(Justify::Center)
|
||||||
/// ));
|
/// ));
|
||||||
///
|
///
|
||||||
/// // With spans
|
/// // With spans
|
||||||
|
@ -129,7 +129,7 @@ fn setup_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
cmd.with_children(|builder| {
|
cmd.with_children(|builder| {
|
||||||
builder.spawn((
|
builder.spawn((
|
||||||
Text2d::new(rect.text),
|
Text2d::new(rect.text),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
TextFont::from_font_size(15.),
|
TextFont::from_font_size(15.),
|
||||||
Transform::from_xyz(0., -0.5 * rect.size.y - 10., 0.),
|
Transform::from_xyz(0., -0.5 * rect.size.y - 10., 0.),
|
||||||
bevy::sprite::Anchor::TOP_CENTER,
|
bevy::sprite::Anchor::TOP_CENTER,
|
||||||
@ -275,7 +275,7 @@ fn setup_texture_atlas(
|
|||||||
cmd.with_children(|builder| {
|
cmd.with_children(|builder| {
|
||||||
builder.spawn((
|
builder.spawn((
|
||||||
Text2d::new(sprite_sheet.text),
|
Text2d::new(sprite_sheet.text),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
TextFont::from_font_size(15.),
|
TextFont::from_font_size(15.),
|
||||||
Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
|
Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
|
||||||
bevy::sprite::Anchor::TOP_CENTER,
|
bevy::sprite::Anchor::TOP_CENTER,
|
||||||
|
@ -94,7 +94,7 @@ fn spawn_sprites(
|
|||||||
children![(
|
children![(
|
||||||
Text2d::new(label),
|
Text2d::new(label),
|
||||||
text_style,
|
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),
|
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
|
||||||
bevy::sprite::Anchor::TOP_CENTER,
|
bevy::sprite::Anchor::TOP_CENTER,
|
||||||
)],
|
)],
|
||||||
|
@ -40,7 +40,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
font_size: 50.0,
|
font_size: 50.0,
|
||||||
..default()
|
..default()
|
||||||
};
|
};
|
||||||
let text_justification = JustifyText::Center;
|
let text_justification = Justify::Center;
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
// Demonstrate changing translation
|
// Demonstrate changing translation
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
@ -78,7 +78,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
children![(
|
children![(
|
||||||
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
|
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
|
||||||
slightly_smaller_text_font.clone(),
|
slightly_smaller_text_font.clone(),
|
||||||
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
|
TextLayout::new(Justify::Left, LineBreak::WordBoundary),
|
||||||
// Wrap text in the rectangle
|
// Wrap text in the rectangle
|
||||||
TextBounds::from(box_size),
|
TextBounds::from(box_size),
|
||||||
// Ensure the text is drawn on top of the box
|
// Ensure the text is drawn on top of the box
|
||||||
@ -94,7 +94,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
children![(
|
children![(
|
||||||
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
|
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
|
||||||
slightly_smaller_text_font.clone(),
|
slightly_smaller_text_font.clone(),
|
||||||
TextLayout::new(JustifyText::Left, LineBreak::AnyCharacter),
|
TextLayout::new(Justify::Left, LineBreak::AnyCharacter),
|
||||||
// Wrap text in the rectangle
|
// Wrap text in the rectangle
|
||||||
TextBounds::from(other_box_size),
|
TextBounds::from(other_box_size),
|
||||||
// Ensure the text is drawn on top of the box
|
// Ensure the text is drawn on top of the box
|
||||||
@ -104,11 +104,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
|
|
||||||
// Demonstrate font smoothing off
|
// Demonstrate font smoothing off
|
||||||
commands.spawn((
|
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
|
slightly_smaller_text_font
|
||||||
.clone()
|
.clone()
|
||||||
.with_font_smoothing(FontSmoothing::None),
|
.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)),
|
Transform::from_translation(Vec3::new(-400.0, -250.0, 0.0)),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ fn create_label(
|
|||||||
commands.spawn((
|
commands.spawn((
|
||||||
Text2d::new(text),
|
Text2d::new(text),
|
||||||
text_style,
|
text_style,
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Transform {
|
Transform {
|
||||||
translation: Vec3::new(translation.0, translation.1, translation.2),
|
translation: Vec3::new(translation.0, translation.1, translation.2),
|
||||||
..default()
|
..default()
|
||||||
|
@ -180,7 +180,7 @@ fn setup_image_viewer_scene(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(Color::BLACK),
|
TextColor(Color::BLACK),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Node {
|
Node {
|
||||||
align_self: AlignSelf::Center,
|
align_self: AlignSelf::Center,
|
||||||
margin: UiRect::all(Val::Auto),
|
margin: UiRect::all(Val::Auto),
|
||||||
|
@ -151,7 +151,7 @@ fn setup(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(Color::Srgba(Srgba::RED)),
|
TextColor(Color::Srgba(Srgba::RED)),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
))
|
))
|
||||||
// Mark as an animation target.
|
// Mark as an animation target.
|
||||||
.insert(AnimationTarget {
|
.insert(AnimationTarget {
|
||||||
|
@ -277,7 +277,7 @@ fn setup_node_rects(commands: &mut Commands) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(ANTIQUE_WHITE.into()),
|
TextColor(ANTIQUE_WHITE.into()),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ fn add_mask_group_control(
|
|||||||
} else {
|
} else {
|
||||||
selected_button_text_style.clone()
|
selected_button_text_style.clone()
|
||||||
},
|
},
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Node {
|
Node {
|
||||||
flex_grow: 1.0,
|
flex_grow: 1.0,
|
||||||
margin: UiRect::vertical(Val::Px(3.0)),
|
margin: UiRect::vertical(Val::Px(3.0)),
|
||||||
|
@ -54,7 +54,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
|
|||||||
for (per_frame, event) in reader.read().enumerate() {
|
for (per_frame, event) in reader.read().enumerate() {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Text2d::new(event.0.to_string()),
|
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),
|
Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ fn setup_ui(mut commands: Commands) {
|
|||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Text::default(),
|
Text::default(),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Node {
|
Node {
|
||||||
align_self: AlignSelf::Center,
|
align_self: AlignSelf::Center,
|
||||||
justify_self: JustifySelf::Center,
|
justify_self: JustifySelf::Center,
|
||||||
|
@ -379,7 +379,7 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
|
|||||||
children![(
|
children![(
|
||||||
Text::default(),
|
Text::default(),
|
||||||
HeaderText,
|
HeaderText,
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
children![
|
children![
|
||||||
TextSpan::new("Primitive: "),
|
TextSpan::new("Primitive: "),
|
||||||
TextSpan(format!("{text}", text = PrimitiveSelected::default())),
|
TextSpan(format!("{text}", text = PrimitiveSelected::default())),
|
||||||
|
@ -158,7 +158,7 @@ fn setup_scene(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor::BLACK,
|
TextColor::BLACK,
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ fn setup(mut commands: Commands, args: Res<Args>) {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let text_block = TextLayout {
|
let text_block = TextLayout {
|
||||||
justify: JustifyText::Left,
|
justify: Justify::Left,
|
||||||
linebreak: LineBreak::AnyCharacter,
|
linebreak: LineBreak::AnyCharacter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ struct Args {
|
|||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
no_frustum_culling: bool,
|
no_frustum_culling: bool,
|
||||||
|
|
||||||
/// whether the text should use `JustifyText::Center`.
|
/// whether the text should use `Justify::Center`.
|
||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
center: bool,
|
center: bool,
|
||||||
}
|
}
|
||||||
@ -132,9 +132,9 @@ fn setup(mut commands: Commands, font: Res<FontHandle>, args: Res<Args>) {
|
|||||||
random_text_font(&mut rng, &args, font.0.clone()),
|
random_text_font(&mut rng, &args, font.0.clone()),
|
||||||
TextColor(color.into()),
|
TextColor(color.into()),
|
||||||
TextLayout::new_with_justify(if args.center {
|
TextLayout::new_with_justify(if args.center {
|
||||||
JustifyText::Center
|
Justify::Center
|
||||||
} else {
|
} else {
|
||||||
JustifyText::Left
|
Justify::Left
|
||||||
}),
|
}),
|
||||||
Transform {
|
Transform {
|
||||||
translation,
|
translation,
|
||||||
|
@ -69,7 +69,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
.spawn((
|
.spawn((
|
||||||
Text2d::default(),
|
Text2d::default(),
|
||||||
TextLayout {
|
TextLayout {
|
||||||
justify: JustifyText::Center,
|
justify: Justify::Center,
|
||||||
linebreak: LineBreak::AnyCharacter,
|
linebreak: LineBreak::AnyCharacter,
|
||||||
},
|
},
|
||||||
TextBounds::default(),
|
TextBounds::default(),
|
||||||
|
@ -151,10 +151,10 @@ mod text {
|
|||||||
commands.spawn((Camera2d, DespawnOnExitState(super::Scene::Text)));
|
commands.spawn((Camera2d, DespawnOnExitState(super::Scene::Text)));
|
||||||
|
|
||||||
for (i, justify) in [
|
for (i, justify) in [
|
||||||
JustifyText::Left,
|
Justify::Left,
|
||||||
JustifyText::Right,
|
Justify::Right,
|
||||||
JustifyText::Center,
|
Justify::Center,
|
||||||
JustifyText::Justified,
|
Justify::Justified,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -196,7 +196,7 @@ mod text {
|
|||||||
fn spawn_anchored_text(
|
fn spawn_anchored_text(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
dest: Vec3,
|
dest: Vec3,
|
||||||
justify: JustifyText,
|
justify: Justify,
|
||||||
bounds: Option<TextBounds>,
|
bounds: Option<TextBounds>,
|
||||||
) {
|
) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -372,7 +372,7 @@ mod text_wrap {
|
|||||||
for (j, message) in messages.into_iter().enumerate() {
|
for (j, message) in messages.into_iter().enumerate() {
|
||||||
commands.entity(root).with_child((
|
commands.entity(root).with_child((
|
||||||
Text(message.clone()),
|
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.)),
|
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.3, 0., 0.)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(Color::srgb(0.85, 0.85, 0.85)),
|
TextColor(Color::srgb(0.85, 0.85, 0.85)),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Text::default(),
|
Text::default(),
|
||||||
@ -111,7 +111,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(virtual_color),
|
TextColor(virtual_color),
|
||||||
TextLayout::new_with_justify(JustifyText::Right),
|
TextLayout::new_with_justify(Justify::Right),
|
||||||
VirtualTime,
|
VirtualTime,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -186,7 +186,7 @@ fn setup_ui(
|
|||||||
Text::new(button_name),
|
Text::new(button_name),
|
||||||
// And center the text if it flows onto multiple lines
|
// And center the text if it flows onto multiple lines
|
||||||
TextLayout {
|
TextLayout {
|
||||||
justify: JustifyText::Center,
|
justify: Justify::Center,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
@ -99,7 +99,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
parent.spawn((
|
parent.spawn((
|
||||||
Text::new("Use the panel on the right to change the Display and Visibility properties for the respective nodes of the panel on the left"),
|
Text::new("Use the panel on the right to change the Display and Visibility properties for the respective nodes of the panel on the left"),
|
||||||
text_font.clone(),
|
text_font.clone(),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Node {
|
Node {
|
||||||
margin: UiRect::bottom(Val::Px(10.)),
|
margin: UiRect::bottom(Val::Px(10.)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -153,13 +153,13 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
Text::new("Display::None\nVisibility::Hidden\nVisibility::Inherited"),
|
Text::new("Display::None\nVisibility::Hidden\nVisibility::Inherited"),
|
||||||
text_font.clone(),
|
text_font.clone(),
|
||||||
TextColor(HIDDEN_COLOR),
|
TextColor(HIDDEN_COLOR),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
));
|
));
|
||||||
builder.spawn((
|
builder.spawn((
|
||||||
Text::new("-\n-\n-"),
|
Text::new("-\n-\n-"),
|
||||||
text_font.clone(),
|
text_font.clone(),
|
||||||
TextColor(DARK_GRAY.into()),
|
TextColor(DARK_GRAY.into()),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
));
|
));
|
||||||
builder.spawn((Text::new("The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible."), text_font));
|
builder.spawn((Text::new("The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible."), text_font));
|
||||||
});
|
});
|
||||||
@ -396,7 +396,7 @@ where
|
|||||||
builder.spawn((
|
builder.spawn((
|
||||||
Text(format!("{}::{:?}", Target::<T>::NAME, T::default())),
|
Text(format!("{}::{:?}", Target::<T>::NAME, T::default())),
|
||||||
text_font,
|
text_font,
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ fn spawn_button(
|
|||||||
} else {
|
} else {
|
||||||
UNHOVERED_TEXT_COLOR
|
UNHOVERED_TEXT_COLOR
|
||||||
}),
|
}),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
},
|
},
|
||||||
TextShadow::default(),
|
TextShadow::default(),
|
||||||
// Set the justification of the Text
|
// Set the justification of the Text
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
// Set the style of the Node itself.
|
// Set the style of the Node itself.
|
||||||
Node {
|
Node {
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
|
@ -43,7 +43,7 @@ fn setup(mut commands: Commands) {
|
|||||||
.spawn((
|
.spawn((
|
||||||
Text::default(),
|
Text::default(),
|
||||||
TextLayout {
|
TextLayout {
|
||||||
justify: JustifyText::Center,
|
justify: Justify::Center,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
@ -64,7 +64,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
));
|
));
|
||||||
builder.spawn((
|
builder.spawn((
|
||||||
Text::new(
|
Text::new(
|
||||||
"This text is right-justified. The `JustifyText` component controls the horizontal alignment of the lines of multi-line text relative to each other, and does not affect the text node's position in the UI layout.",
|
"This text is right-justified. The `Justify` component controls the horizontal alignment of the lines of multi-line text relative to each other, and does not affect the text node's position in the UI layout.",
|
||||||
),
|
),
|
||||||
TextFont {
|
TextFont {
|
||||||
font: font.clone(),
|
font: font.clone(),
|
||||||
@ -72,7 +72,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(YELLOW.into()),
|
TextColor(YELLOW.into()),
|
||||||
TextLayout::new_with_justify(JustifyText::Right),
|
TextLayout::new_with_justify(Justify::Right),
|
||||||
Node {
|
Node {
|
||||||
max_width: Val::Px(300.),
|
max_width: Val::Px(300.),
|
||||||
..default()
|
..default()
|
||||||
@ -114,7 +114,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(Color::srgb(0.8, 0.2, 0.7)),
|
TextColor(Color::srgb(0.8, 0.2, 0.7)),
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
Node {
|
Node {
|
||||||
max_width: Val::Px(400.),
|
max_width: Val::Px(400.),
|
||||||
..default()
|
..default()
|
||||||
@ -130,7 +130,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextColor(YELLOW.into()),
|
TextColor(YELLOW.into()),
|
||||||
TextLayout::new_with_justify(JustifyText::Left),
|
TextLayout::new_with_justify(Justify::Left),
|
||||||
Node {
|
Node {
|
||||||
max_width: Val::Px(300.),
|
max_width: Val::Px(300.),
|
||||||
..default()
|
..default()
|
||||||
@ -145,7 +145,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
font_size: 29.0,
|
font_size: 29.0,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
TextLayout::new_with_justify(JustifyText::Justified),
|
TextLayout::new_with_justify(Justify::Justified),
|
||||||
TextColor(GREEN_YELLOW.into()),
|
TextColor(GREEN_YELLOW.into()),
|
||||||
Node {
|
Node {
|
||||||
max_width: Val::Px(300.),
|
max_width: Val::Px(300.),
|
||||||
|
@ -117,7 +117,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
commands.entity(column_id).with_child((
|
commands.entity(column_id).with_child((
|
||||||
Text(message.clone()),
|
Text(message.clone()),
|
||||||
text_font.clone(),
|
text_font.clone(),
|
||||||
TextLayout::new(JustifyText::Left, linebreak),
|
TextLayout::new(Justify::Left, linebreak),
|
||||||
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.2, 0., 0.)),
|
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.2, 0., 0.)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
8
release-content/migration-guides/rename-justifytext.md
Normal file
8
release-content/migration-guides/rename-justifytext.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
title: Renamed `JustifyText` to `Justify`
|
||||||
|
pull_requests: [19522]
|
||||||
|
---
|
||||||
|
|
||||||
|
`JustifyText` has been renamed to `Justify`.
|
||||||
|
|
||||||
|
The `-Text` suffix was inconsistent with the names of other `bevy_text` types and unnecessary since it's natural to assume `Justify` refers to text justification.
|
Loading…
Reference in New Issue
Block a user