@@ -25,18 +25,20 @@ impl Default for CosmicBuffer {
25
25
}
26
26
}
27
27
28
- /// A sub-entity of a [`TextBlock `].
28
+ /// A sub-entity of a [`ComputedTextBlock `].
29
29
///
30
30
/// Returned by [`ComputedTextBlock::entities`].
31
31
#[ derive( Debug , Copy , Clone ) ]
32
32
pub struct TextEntity {
33
33
/// The entity.
34
34
pub entity : Entity ,
35
- /// Records the hierarchy depth of the entity within a `TextBlock `.
35
+ /// Records the hierarchy depth of the entity within a `TextLayout `.
36
36
pub depth : usize ,
37
37
}
38
38
39
- /// Computed information for a [`TextBlock`].
39
+ /// Computed information for a text block.
40
+ ///
41
+ /// See [`TextLayout`].
40
42
///
41
43
/// Automatically updated by 2d and UI text systems.
42
44
#[ derive( Component , Debug , Clone ) ]
@@ -45,7 +47,7 @@ pub struct ComputedTextBlock {
45
47
///
46
48
/// This is private because buffer contents are always refreshed from ECS state when writing glyphs to
47
49
/// `TextLayoutInfo`. If you want to control the buffer contents manually or use the `cosmic-text`
48
- /// editor, then you need to not use `TextBlock ` and instead manually implement the conversion to
50
+ /// editor, then you need to not use `TextLayout ` and instead manually implement the conversion to
49
51
/// `TextLayoutInfo`.
50
52
pub ( crate ) buffer : CosmicBuffer ,
51
53
/// Entities for all text spans in the block, including the root-level text.
@@ -55,12 +57,12 @@ pub struct ComputedTextBlock {
55
57
/// Flag set when any change has been made to this block that should cause it to be rerendered.
56
58
///
57
59
/// Includes:
58
- /// - [`TextBlock `] changes.
60
+ /// - [`TextLayout `] changes.
59
61
/// - [`TextStyle`] or `Text2d`/`Text`/`TextSpan` changes anywhere in the block's entity hierarchy.
60
62
// TODO: This encompasses both structural changes like font size or justification and non-structural
61
63
// changes like text color and font smoothing. This field currently causes UI to 'remeasure' text, even if
62
64
// the actual changes are non-structural and can be handled by only rerendering and not remeasuring. A full
63
- // solution would probably require splitting TextBlock and TextStyle into structural/non-structural
65
+ // solution would probably require splitting TextLayout and TextStyle into structural/non-structural
64
66
// components for more granular change detection. A cost/benefit analysis is needed.
65
67
pub ( crate ) needs_rerender : bool ,
66
68
}
@@ -103,57 +105,57 @@ impl Default for ComputedTextBlock {
103
105
#[ derive( Component , Debug , Copy , Clone , Default , Reflect ) ]
104
106
#[ reflect( Component , Default , Debug ) ]
105
107
#[ require( ComputedTextBlock , TextLayoutInfo ) ]
106
- pub struct TextBlock {
108
+ pub struct TextLayout {
107
109
/// The text's internal alignment.
108
110
/// Should not affect its position within a container.
109
111
pub justify : JustifyText ,
110
112
/// How the text should linebreak when running out of the bounds determined by `max_size`.
111
113
pub linebreak : LineBreak ,
112
114
}
113
115
114
- impl TextBlock {
115
- /// Makes a new [`TextBlock `].
116
+ impl TextLayout {
117
+ /// Makes a new [`TextLayout `].
116
118
pub const fn new ( justify : JustifyText , linebreak : LineBreak ) -> Self {
117
119
Self { justify, linebreak }
118
120
}
119
121
120
- /// Makes a new [`TextBlock `] with the specified [`JustifyText`].
122
+ /// Makes a new [`TextLayout `] with the specified [`JustifyText`].
121
123
pub fn new_with_justify ( justify : JustifyText ) -> Self {
122
124
Self :: default ( ) . with_justify ( justify)
123
125
}
124
126
125
- /// Makes a new [`TextBlock `] with the specified [`LineBreak`].
127
+ /// Makes a new [`TextLayout `] with the specified [`LineBreak`].
126
128
pub fn new_with_linebreak ( linebreak : LineBreak ) -> Self {
127
129
Self :: default ( ) . with_linebreak ( linebreak)
128
130
}
129
131
130
- /// Makes a new [`TextBlock `] with soft wrapping disabled.
132
+ /// Makes a new [`TextLayout `] with soft wrapping disabled.
131
133
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
132
134
pub fn new_with_no_wrap ( ) -> Self {
133
135
Self :: default ( ) . with_no_wrap ( )
134
136
}
135
137
136
- /// Returns this [`TextBlock `] with the specified [`JustifyText`].
138
+ /// Returns this [`TextLayout `] with the specified [`JustifyText`].
137
139
pub const fn with_justify ( mut self , justify : JustifyText ) -> Self {
138
140
self . justify = justify;
139
141
self
140
142
}
141
143
142
- /// Returns this [`TextBlock `] with the specified [`LineBreak`].
144
+ /// Returns this [`TextLayout `] with the specified [`LineBreak`].
143
145
pub const fn with_linebreak ( mut self , linebreak : LineBreak ) -> Self {
144
146
self . linebreak = linebreak;
145
147
self
146
148
}
147
149
148
- /// Returns this [`TextBlock `] with soft wrapping disabled.
150
+ /// Returns this [`TextLayout `] with soft wrapping disabled.
149
151
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
150
152
pub const fn with_no_wrap ( mut self ) -> Self {
151
153
self . linebreak = LineBreak :: NoWrap ;
152
154
self
153
155
}
154
156
}
155
157
156
- /// A span of UI text in a tree of spans under an entity with [`TextBlock`], such as `Text` or `Text2d`.
158
+ /// A span of UI text in a tree of spans under an entity with [`TextLayout`] and `Text` or `Text2d`.
157
159
///
158
160
/// Spans are collected in hierarchy traversal order into a [`ComputedTextBlock`] for layout.
159
161
///
@@ -163,13 +165,13 @@ impl TextBlock {
163
165
# use bevy_color::Color;
164
166
# use bevy_color::palettes::basic::{RED, BLUE};
165
167
# use bevy_ecs::World;
166
- # use bevy_text::{Font, TextBlock , TextStyle, TextSection};
168
+ # use bevy_text::{Font, TextLayout , TextStyle, TextSection};
167
169
168
170
# let font_handle: Handle<Font> = Default::default();
169
171
# let mut world = World::default();
170
172
#
171
173
world.spawn((
172
- TextBlock ::default(),
174
+ TextLayout ::default(),
173
175
TextStyle {
174
176
font: font_handle.clone().into(),
175
177
font_size: 60.0,
@@ -257,7 +259,7 @@ impl From<JustifyText> for cosmic_text::Align {
257
259
}
258
260
}
259
261
260
- /// `TextStyle` determines the style of a text span within a [`TextBlock `], specifically
262
+ /// `TextStyle` determines the style of a text span within a [`ComputedTextBlock `], specifically
261
263
/// the font face, the font size, and the color.
262
264
#[ derive( Component , Clone , Debug , Reflect ) ]
263
265
#[ reflect( Component , Default , Debug ) ]
@@ -285,7 +287,7 @@ pub struct TextStyle {
285
287
}
286
288
287
289
impl TextStyle {
288
- /// Returns this [`TextBlock `] with the specified [`FontSmoothing`].
290
+ /// Returns this [`TextStyle `] with the specified [`FontSmoothing`].
289
291
pub const fn with_font_smoothing ( mut self , font_smoothing : FontSmoothing ) -> Self {
290
292
self . font_smoothing = font_smoothing;
291
293
self
@@ -358,23 +360,23 @@ pub fn detect_text_needs_rerender<Root: Component>(
358
360
Or < (
359
361
Changed < Root > ,
360
362
Changed < TextStyle > ,
361
- Changed < TextBlock > ,
363
+ Changed < TextLayout > ,
362
364
Changed < Children > ,
363
365
) > ,
364
366
With < Root > ,
365
367
With < TextStyle > ,
366
- With < TextBlock > ,
368
+ With < TextLayout > ,
367
369
) ,
368
370
> ,
369
371
changed_spans : Query <
370
- ( Entity , Option < & Parent > , Has < TextBlock > ) ,
372
+ ( Entity , Option < & Parent > , Has < TextLayout > ) ,
371
373
(
372
374
Or < (
373
375
Changed < TextSpan > ,
374
376
Changed < TextStyle > ,
375
377
Changed < Children > ,
376
378
Changed < Parent > , // Included to detect broken text block hierarchies.
377
- Added < TextBlock > ,
379
+ Added < TextLayout > ,
378
380
) > ,
379
381
With < TextSpan > ,
380
382
With < TextStyle > ,
@@ -389,7 +391,7 @@ pub fn detect_text_needs_rerender<Root: Component>(
389
391
// Root entity:
390
392
// - Root component changed.
391
393
// - TextStyle on root changed.
392
- // - TextBlock changed.
394
+ // - TextLayout changed.
393
395
// - Root children changed (can include additions and removals).
394
396
for root in changed_roots. iter ( ) {
395
397
let Ok ( ( _, Some ( mut computed) , _) ) = computed. get_mut ( root) else {
@@ -406,7 +408,7 @@ pub fn detect_text_needs_rerender<Root: Component>(
406
408
// - Span children changed (can include additions and removals).
407
409
for ( entity, maybe_span_parent, has_text_block) in changed_spans. iter ( ) {
408
410
if has_text_block {
409
- warn_once ! ( "found entity {:?} with a TextSpan that has a TextBlock , which should only be on root \
411
+ warn_once ! ( "found entity {:?} with a TextSpan that has a TextLayout , which should only be on root \
410
412
text entities (that have {}); this warning only prints once",
411
413
entity, core:: any:: type_name:: <Root >( ) ) ;
412
414
}
0 commit comments