Skip to content

Commit 36f4d4d

Browse files
committed
crates compile
1 parent 64bc992 commit 36f4d4d

File tree

15 files changed

+171
-170
lines changed

15 files changed

+171
-170
lines changed

crates/bevy_text/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bevy_asset = { path = "../bevy_asset", version = "0.15.0-dev" }
1818
bevy_color = { path = "../bevy_color", version = "0.15.0-dev" }
1919
bevy_derive = { path = "../bevy_derive", version = "0.15.0-dev" }
2020
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" }
21+
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.15.0-dev" }
2122
bevy_math = { path = "../bevy_math", version = "0.15.0-dev" }
2223
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
2324
"bevy",
@@ -32,6 +33,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
3233
cosmic-text = { version = "0.12", features = ["shape-run-cache"] }
3334
thiserror = "1.0"
3435
serde = { version = "1", features = ["derive"] }
36+
smallvec = "1.13"
3537
unicode-bidi = "0.3.13"
3638
sys-locale = "0.3.0"
3739

crates/bevy_text/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod glyph;
4343
mod pipeline;
4444
mod text;
4545
mod text2d;
46-
mod text_spans;
46+
mod text_blocks;
4747

4848
pub use cosmic_text;
4949

@@ -57,7 +57,7 @@ pub use glyph::*;
5757
pub use pipeline::*;
5858
pub use text::*;
5959
pub use text2d::*;
60-
pub use text_spans::*;
60+
pub use text_blocks::*;
6161

6262
/// The text prelude.
6363
///
@@ -106,10 +106,6 @@ pub enum YAxisOrientation {
106106
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
107107
pub struct Update2dText;
108108

109-
/// A convenient alias for `With<Text>`, for use with
110-
/// [`bevy_render::view::VisibleEntities`].
111-
pub type WithText = With<Text>;
112-
113109
impl Plugin for TextPlugin {
114110
fn build(&self, app: &mut App) {
115111
app.init_asset::<Font>()

crates/bevy_text/src/pipeline.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use bevy_utils::HashMap;
1616
use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
1717

1818
use crate::{
19-
error::TextError, CosmicBuffer, Font, FontAtlasSets, FontSmoothing, JustifyText, LineBreak,
20-
PositionedGlyph, TextBounds, TextSection, TextStyle, YAxisOrientation,
19+
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText,
20+
LineBreak, PositionedGlyph, TextBlock, TextBounds, TextEntity, TextStyle, YAxisOrientation,
2121
};
2222

2323
/// A wrapper resource around a [`cosmic_text::FontSystem`]
@@ -83,7 +83,7 @@ impl TextPipeline {
8383
pub fn update_buffer<'a>(
8484
&mut self,
8585
fonts: &Assets<Font>,
86-
mut text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
86+
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
8787
linebreak: LineBreak,
8888
justify: JustifyText,
8989
bounds: TextBounds,
@@ -197,7 +197,7 @@ impl TextPipeline {
197197
/// Produces a [`TextLayoutInfo`], containing [`PositionedGlyph`]s
198198
/// which contain information for rendering the text.
199199
#[allow(clippy::too_many_arguments)]
200-
pub fn queue_text(
200+
pub fn queue_text<'a>(
201201
&mut self,
202202
layout_info: &mut TextLayoutInfo,
203203
fonts: &Assets<Font>,
@@ -333,7 +333,7 @@ impl TextPipeline {
333333
/// Produces a [`TextMeasureInfo`] which can be used by a layout system
334334
/// to measure the text area on demand.
335335
#[allow(clippy::too_many_arguments)]
336-
pub fn create_text_measure(
336+
pub fn create_text_measure<'a>(
337337
&mut self,
338338
entity: Entity,
339339
fonts: &Assets<Font>,
@@ -360,6 +360,7 @@ impl TextPipeline {
360360
font_system,
361361
)?;
362362

363+
let buffer = &mut computed.buffer;
363364
let min_width_content_size = buffer_dimensions(buffer);
364365

365366
let max_width_content_size = {
@@ -414,13 +415,15 @@ impl TextMeasureInfo {
414415
pub fn compute_size(
415416
&mut self,
416417
bounds: TextBounds,
417-
buffer: &mut Buffer,
418+
computed: &mut ComputedTextBlock,
418419
font_system: &mut cosmic_text::FontSystem,
419420
) -> Vec2 {
420421
// Note that this arbitrarily adjusts the buffer layout. We assume the buffer is always 'refreshed'
421422
// whenever a canonical state is required.
422-
buffer.set_size(font_system, bounds.width, bounds.height);
423-
buffer_dimensions(buffer)
423+
computed
424+
.buffer
425+
.set_size(font_system, bounds.width, bounds.height);
426+
buffer_dimensions(&computed.buffer)
424427
}
425428
}
426429

crates/bevy_text/src/text.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use bevy_asset::Handle;
22
use bevy_color::Color;
33
use bevy_derive::{Deref, DerefMut};
4-
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
4+
use bevy_ecs::{prelude::*, reflect::ReflectComponent};
5+
use bevy_hierarchy::{Children, Parent};
56
use bevy_reflect::prelude::*;
6-
use bevy_utils::default;
77
use cosmic_text::{Buffer, Metrics};
88
use serde::{Deserialize, Serialize};
9+
use smallvec::SmallVec;
910

10-
use crate::Font;
11+
use crate::{Font, TextLayoutInfo};
1112
pub use cosmic_text::{
1213
self, FamilyOwned as FontFamily, Stretch as FontStretch, Style as FontStyle,
1314
Weight as FontWeight,
@@ -26,8 +27,9 @@ impl Default for CosmicBuffer {
2627
/// A sub-entity of a [`TextBlock`].
2728
///
2829
/// Returned by [`ComputedTextBlock::entities`].
29-
#[derive(Default, Debug, Copy, Clone)]
30+
#[derive(Debug, Copy, Clone)]
3031
pub struct TextEntity {
32+
/// The entity.
3133
pub entity: Entity,
3234
/// Records the hierarchy depth of the entity within a `TextBlock`.
3335
pub depth: usize,
@@ -99,7 +101,7 @@ impl Default for ComputedTextBlock {
99101
/// See [`Text2d`] for the core component of 2d text, and `Text` in `bevy_ui` for UI text.
100102
#[derive(Component, Debug, Clone, Default, Reflect)]
101103
#[reflect(Component, Default, Debug)]
102-
#[requires(ComputedTextBlock, TextLayoutInfo)]
104+
#[require(ComputedTextBlock, TextLayoutInfo)]
103105
pub struct TextBlock {
104106
/// The text's internal alignment.
105107
/// Should not affect its position within a container.
@@ -125,24 +127,24 @@ impl TextBlock {
125127
}
126128

127129
/// Makes a new [`TextBlock`] with the specified [`JustifyText`].
128-
pub const fn new_with_justify(justify: JustifyText) -> Self {
130+
pub fn new_with_justify(justify: JustifyText) -> Self {
129131
Self::default().with_justify(justify)
130132
}
131133

132134
/// Makes a new [`TextBlock`] with the specified [`LineBreak`].
133-
pub const fn new_with_linebreak(linebreak: LineBreak) -> Self {
135+
pub fn new_with_linebreak(linebreak: LineBreak) -> Self {
134136
Self::default().with_linebreak(linebreak)
135137
}
136138

137139
/// Makes a new [`TextBlock`] with the specified [`FontSmoothing`].
138-
pub const fn new_with_font_smoothing(font_smoothing: FontSmoothing) -> Self {
140+
pub fn new_with_font_smoothing(font_smoothing: FontSmoothing) -> Self {
139141
Self::default().with_font_smoothing(font_smoothing)
140142
}
141143

142144
/// Makes a new [`TextBlock`] with soft wrapping disabled.
143145
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
144-
pub const fn new_with_no_wrap() -> Self {
145-
Self::default().with_no_wrap(linebreak)
146+
pub fn new_with_no_wrap() -> Self {
147+
Self::default().with_no_wrap()
146148
}
147149

148150
/// Returns this [`TextBlock`] with the specified [`JustifyText`].
@@ -307,9 +309,11 @@ pub fn detect_text_needs_rerender<Root: Component, Span: Component>(
307309
>,
308310
changed_spans: Query<
309311
&Parent,
310-
Or<(Changed<Span>, Changed<TextStyle>, Changed<Children>)>,
311-
With<Span>,
312-
With<TextStyle>,
312+
(
313+
Or<(Changed<Span>, Changed<TextStyle>, Changed<Children>)>,
314+
With<Span>,
315+
With<TextStyle>,
316+
),
313317
>,
314318
mut computed: Query<(Option<&Parent>, Option<&mut ComputedTextBlock>)>,
315319
) {
@@ -341,7 +345,7 @@ pub fn detect_text_needs_rerender<Root: Component, Span: Component>(
341345
let Ok((maybe_parent, maybe_computed)) = computed.get_mut(parent) else {
342346
break;
343347
};
344-
if let Some(computed) = maybe_computed {
348+
if let Some(mut computed) = maybe_computed {
345349
computed.needs_rerender = true;
346350
break;
347351
}

crates/bevy_text/src/text2d.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
use crate::pipeline::CosmicFontSystem;
22
use crate::{
3-
CosmicBuffer, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, Text, TextBounds,
4-
TextError, TextLayoutInfo, TextPipeline, YAxisOrientation,
3+
ComputedTextBlock, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, TextBlock,
4+
TextBlocks, TextBounds, TextError, TextLayoutInfo, TextPipeline, TextSpanReader, TextStyle,
5+
YAxisOrientation,
56
};
67
use bevy_asset::Assets;
78
use bevy_color::LinearRgba;
9+
use bevy_derive::{Deref, DerefMut};
10+
use bevy_ecs::component::Component;
811
use bevy_ecs::{
9-
bundle::Bundle,
1012
change_detection::{DetectChanges, Ref},
1113
entity::Entity,
1214
event::EventReader,
13-
prelude::With,
15+
prelude::{ReflectComponent, With},
1416
query::{Changed, Without},
1517
system::{Commands, Local, Query, Res, ResMut},
1618
};
1719
use bevy_math::Vec2;
20+
use bevy_reflect::{prelude::ReflectDefault, Reflect};
21+
use bevy_render::view::Visibility;
1822
use bevy_render::{
1923
primitives::Aabb,
2024
texture::Image,
21-
view::{InheritedVisibility, NoFrustumCulling, ViewVisibility, Visibility},
25+
view::{NoFrustumCulling, ViewVisibility},
2226
Extract,
2327
};
2428
use bevy_sprite::{Anchor, ExtractedSprite, ExtractedSprites, SpriteSource, TextureAtlasLayout};
25-
use bevy_transform::prelude::{GlobalTransform, Transform};
29+
use bevy_transform::components::Transform;
30+
use bevy_transform::prelude::GlobalTransform;
2631
use bevy_utils::HashSet;
2732
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
2833

@@ -89,6 +94,12 @@ impl Text2d {
8994
}
9095
}
9196

97+
impl TextSpanReader for Text2d {
98+
fn read_span(&self) -> &str {
99+
self.as_str()
100+
}
101+
}
102+
92103
impl From<&str> for Text2d {
93104
fn from(value: &str) -> Self {
94105
Self(String::from(value))
@@ -134,9 +145,9 @@ world.spawn((
134145
));
135146
```
136147
*/
137-
#[derive(Component, Clone, Debug, Default, Reflect)]
148+
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
138149
#[reflect(Component, Default, Debug)]
139-
#[require(TextStyle, Visibility = Visibility::Hidden, Transform)]
150+
#[require(TextStyle, Visibility(visibility_hidden), Transform)]
140151
pub struct TextSpan2d(pub String);
141152

142153
impl TextSpanReader for TextSpan2d {
@@ -145,6 +156,10 @@ impl TextSpanReader for TextSpan2d {
145156
}
146157
}
147158

159+
fn visibility_hidden() -> Visibility {
160+
Visibility::Hidden
161+
}
162+
148163
/// This system extracts the sprites from the 2D text components and adds them to the
149164
/// "render world".
150165
pub fn extract_text2d_sprite(
@@ -204,6 +219,7 @@ pub fn extract_text2d_sprite(
204219
computed_block
205220
.entities()
206221
.get(*span_index)
222+
.map(|t| t.entity)
207223
.unwrap_or(Entity::PLACEHOLDER),
208224
)
209225
.map(|style| LinearRgba::from(style.color))
@@ -251,13 +267,12 @@ pub fn update_text2d_layout(
251267
mut text_pipeline: ResMut<TextPipeline>,
252268
mut text_query: Query<(
253269
Entity,
254-
Ref<Text2d>,
255270
Ref<TextBlock>,
256271
Ref<TextBounds>,
257272
&mut TextLayoutInfo,
258273
&mut ComputedTextBlock,
259274
)>,
260-
mut spans: TextSpans<TextSpan2d>,
275+
mut blocks: TextBlocks<Text2d, TextSpan2d>,
261276
mut font_system: ResMut<CosmicFontSystem>,
262277
mut swash_cache: ResMut<SwashCache>,
263278
) {
@@ -272,14 +287,14 @@ pub fn update_text2d_layout(
272287

273288
let inverse_scale_factor = scale_factor.recip();
274289

275-
for (entity, text, block, bounds, text_layout_info, mut computed) in &mut text_query {
290+
for (entity, block, bounds, text_layout_info, mut computed) in &mut text_query {
276291
if factor_changed
277292
|| computed.needs_rerender()
278293
|| bounds.is_changed()
279294
|| queue.remove(&entity)
280295
{
281296
let text_bounds = TextBounds {
282-
width: if text.linebreak == LineBreak::NoWrap {
297+
width: if block.linebreak == LineBreak::NoWrap {
283298
None
284299
} else {
285300
bounds.width.map(|width| scale_value(width, scale_factor))
@@ -293,9 +308,9 @@ pub fn update_text2d_layout(
293308
match text_pipeline.queue_text(
294309
text_layout_info,
295310
&fonts,
296-
spans.iter_from_base(entity, text.as_str(), text_style, maybe_children),
311+
blocks.iter(entity),
297312
scale_factor.into(),
298-
block,
313+
&block,
299314
text_bounds,
300315
&mut font_atlas_sets,
301316
&mut texture_atlases,

0 commit comments

Comments
 (0)