-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Make each TextSection
its own entity.
#14572
Changes from all commits
72967ea
cfa3db0
bca4cf6
388ab63
6482b45
67d9737
548fd5a
abbaac1
e231822
49ae77c
7cda895
345bc14
dcc89cf
6a8bfbd
25d230e
57d4dc9
ec5d3d6
e15f9c5
7b1a490
4a327a8
d2948c5
f8cd239
0826981
fb550c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,6 @@ impl Default for CosmicBuffer { | |
#[derive(Component, Debug, Clone, Default, Reflect)] | ||
#[reflect(Component, Default)] | ||
pub struct Text { | ||
/// The text's sections | ||
pub sections: Vec<TextSection>, | ||
/// The text's internal alignment. | ||
/// Should not affect its position within a container. | ||
pub justify: JustifyText, | ||
|
@@ -39,79 +37,6 @@ pub struct Text { | |
} | ||
|
||
impl Text { | ||
/// Constructs a [`Text`] with a single section. | ||
/// | ||
/// ``` | ||
/// # use bevy_asset::Handle; | ||
/// # use bevy_color::Color; | ||
/// # use bevy_text::{Font, Text, TextStyle, JustifyText}; | ||
/// # | ||
/// # let font_handle: Handle<Font> = Default::default(); | ||
/// # | ||
/// // Basic usage. | ||
/// let hello_world = Text::from_section( | ||
/// // Accepts a String or any type that converts into a String, such as &str. | ||
/// "hello world!", | ||
/// TextStyle { | ||
/// font: font_handle.clone().into(), | ||
/// font_size: 60.0, | ||
/// color: Color::WHITE, | ||
/// }, | ||
/// ); | ||
/// | ||
/// let hello_bevy = Text::from_section( | ||
/// "hello world\nand bevy!", | ||
/// TextStyle { | ||
/// font: font_handle.into(), | ||
/// font_size: 60.0, | ||
/// color: Color::WHITE, | ||
/// }, | ||
/// ) // You can still add text justifaction. | ||
/// .with_justify(JustifyText::Center); | ||
/// ``` | ||
pub fn from_section(value: impl Into<String>, style: TextStyle) -> Self { | ||
Self { | ||
sections: vec![TextSection::new(value, style)], | ||
..default() | ||
} | ||
} | ||
|
||
/// Constructs a [`Text`] from a list of sections. | ||
/// | ||
/// ``` | ||
/// # use bevy_asset::Handle; | ||
/// # use bevy_color::Color; | ||
/// # use bevy_color::palettes::basic::{RED, BLUE}; | ||
/// # use bevy_text::{Font, Text, TextStyle, TextSection}; | ||
/// # | ||
/// # let font_handle: Handle<Font> = Default::default(); | ||
/// # | ||
/// let hello_world = Text::from_sections([ | ||
/// TextSection::new( | ||
/// "Hello, ", | ||
/// TextStyle { | ||
/// font: font_handle.clone().into(), | ||
/// font_size: 60.0, | ||
/// color: BLUE.into(), | ||
/// }, | ||
/// ), | ||
/// TextSection::new( | ||
/// "World!", | ||
/// TextStyle { | ||
/// font: font_handle.into(), | ||
/// font_size: 60.0, | ||
/// color: RED.into(), | ||
/// }, | ||
/// ), | ||
/// ]); | ||
/// ``` | ||
pub fn from_sections(sections: impl IntoIterator<Item = TextSection>) -> Self { | ||
Self { | ||
sections: sections.into_iter().collect(), | ||
..default() | ||
} | ||
} | ||
|
||
/// Returns this [`Text`] with a new [`JustifyText`]. | ||
pub const fn with_justify(mut self, justify: JustifyText) -> Self { | ||
self.justify = justify; | ||
|
@@ -127,7 +52,7 @@ impl Text { | |
} | ||
|
||
/// Contains the value of the text in a section and how it should be styled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first time we are adding a parent/child hierarchy requirement as far as I know, the docs should indicate this relationship on the related components. Also with this change, the name "Text" is actually more confusing than helping, since it only contains the information for how text will be justified, and contains no text whatsoever |
||
#[derive(Debug, Default, Clone, Reflect)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same on this component, should probably indicate that this component is required to be a child of the other Component. |
||
#[derive(Component, Debug, Default, Clone, Reflect)] | ||
#[reflect(Default)] | ||
pub struct TextSection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be split up I think, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how I feel about that, it would require a LOT more changes, that I don't want to update 100 examples for again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know but I think it's really necessary. Maybe if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. honestly great idea! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Different styling options, with Text2d style propagation and responsive sizes might not make sense or need different solutions. More granular change detection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ickshonpe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree on splitting this, strongly feel this should be moved to followup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I've no problem with moving this to a followup, it would be good if we can avoid multiple rewrites of the api and examples though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably should be split up more even, previously it's really bugged me how changing the colour of a single section causes a relayout of the whole text node. Separate |
||
/// The content (in `String` form) of the text in the section. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion seems confusing because the component is also used in
Text2dBundle
, and we don't use this naming convention in any other UI bundles.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we think of
TextLayout
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go with
TextLayout
, makes the most sense to me.