Skip to content

Text renamings #19444

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 17 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
4 changes: 2 additions & 2 deletions crates/bevy_text/src/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_reflect::Reflect;
///
/// Contains information about how and where to render a glyph.
///
/// Used in [`TextPipeline::queue_text`](crate::TextPipeline::queue_text) and [`crate::TextLayoutInfo`] for rendering glyphs.
/// Used in [`TextPipeline::queue_text`](crate::TextPipeline::queue_text) and [`crate::ComputedTextLayout`] for rendering glyphs.
#[derive(Debug, Clone, Reflect)]
#[reflect(Clone)]
pub struct PositionedGlyph {
Expand All @@ -19,7 +19,7 @@ pub struct PositionedGlyph {
pub size: Vec2,
/// Information about the glyph's atlas.
pub atlas_info: GlyphAtlasInfo,
/// The index of the glyph in the [`ComputedTextBlock`](crate::ComputedTextBlock)'s tracked spans.
/// The index of the glyph in the [`TextBuffer`](crate::TextBuffer)'s tracked spans.
pub span_index: usize,
/// The index of the glyph's line.
pub line_index: usize,
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! 1. updates a [`Buffer`](cosmic_text::Buffer) from the [`TextSpan`]s, generating new [`FontAtlasSet`]s if necessary.
//! 2. iterates over each glyph in the [`Buffer`](cosmic_text::Buffer) to create a [`PositionedGlyph`],
//! retrieving glyphs from the cache, or rasterizing to a [`FontAtlas`] if necessary.
//! 3. [`PositionedGlyph`]s are stored in a [`TextLayoutInfo`],
//! 3. [`PositionedGlyph`]s are stored in a [`ComputedTextLayout`],
//! which contains all the information that downstream systems need for rendering.

extern crate alloc;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub mod prelude {
#[doc(hidden)]
pub use crate::{
Font, JustifyText, LineBreak, Text2d, Text2dReader, Text2dWriter, TextColor, TextError,
TextFont, TextLayout, TextSpan,
TextFont, TextSpan,
};
}

Expand Down Expand Up @@ -105,8 +105,9 @@ impl Plugin for TextPlugin {
.register_type::<TextBackgroundColor>()
.register_type::<TextSpan>()
.register_type::<TextBounds>()
.register_type::<TextLayout>()
.register_type::<ComputedTextBlock>()
.register_type::<JustifyText>()
.register_type::<LineBreak>()
.register_type::<TextBuffer>()
.register_type::<TextEntity>()
.init_asset_loader::<FontLoader>()
.init_resource::<FontAtlasSets>()
Expand Down
42 changes: 22 additions & 20 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, Font, FontAtlasSets, FontSmoothing, JustifyText, LineBreak, PositionedGlyph,
TextBounds, TextBuffer, TextEntity, TextFont,
};

/// A wrapper resource around a [`cosmic_text::FontSystem`]
Expand Down Expand Up @@ -91,7 +91,7 @@ impl TextPipeline {
justify: JustifyText,
bounds: TextBounds,
scale_factor: f64,
computed: &mut ComputedTextBlock,
text_buffer: &mut TextBuffer,
font_system: &mut CosmicFontSystem,
) -> Result<(), TextError> {
let font_system = &mut font_system.0;
Expand All @@ -106,11 +106,11 @@ impl TextPipeline {
.map(|_| -> (usize, &str, &TextFont, FontFaceInfo, Color) { unreachable!() })
.collect();

computed.entities.clear();
text_buffer.entities.clear();

for (span_index, (entity, depth, span, text_font, color)) in text_spans.enumerate() {
// Save this span entity in the computed text block.
computed.entities.push(TextEntity { entity, depth });
text_buffer.entities.push(TextEntity { entity, depth });

if span.is_empty() {
continue;
Expand Down Expand Up @@ -176,7 +176,7 @@ impl TextPipeline {
});

// Update the buffer.
let buffer = &mut computed.buffer;
let buffer = &mut text_buffer.buffer;
buffer.set_metrics_and_size(font_system, metrics, bounds.width, bounds.height);

buffer.set_wrap(
Expand Down Expand Up @@ -219,20 +219,21 @@ impl TextPipeline {

/// Queues text for rendering
///
/// Produces a [`TextLayoutInfo`], containing [`PositionedGlyph`]s
/// Produces a [`ComputedTextLayout`], containing [`PositionedGlyph`]s
/// which contain information for rendering the text.
pub fn queue_text<'a>(
&mut self,
layout_info: &mut TextLayoutInfo,
layout_info: &mut ComputedTextLayout,
fonts: &Assets<Font>,
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextFont, Color)>,
scale_factor: f64,
layout: &TextLayout,
linebreak: LineBreak,
justify: JustifyText,
bounds: TextBounds,
font_atlas_sets: &mut FontAtlasSets,
texture_atlases: &mut Assets<TextureAtlasLayout>,
textures: &mut Assets<Image>,
computed: &mut ComputedTextBlock,
computed: &mut TextBuffer,
font_system: &mut CosmicFontSystem,
swash_cache: &mut SwashCache,
) -> Result<(), TextError> {
Expand All @@ -253,8 +254,8 @@ impl TextPipeline {
let update_result = self.update_buffer(
fonts,
text_spans,
layout.linebreak,
layout.justify,
linebreak,
justify,
bounds,
scale_factor,
computed,
Expand Down Expand Up @@ -396,8 +397,9 @@ impl TextPipeline {
fonts: &Assets<Font>,
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextFont, Color)>,
scale_factor: f64,
layout: &TextLayout,
computed: &mut ComputedTextBlock,
linebreak: LineBreak,
justify: JustifyText,
computed: &mut TextBuffer,
font_system: &mut CosmicFontSystem,
) -> Result<TextMeasureInfo, TextError> {
const MIN_WIDTH_CONTENT_BOUNDS: TextBounds = TextBounds::new_horizontal(0.0);
Expand All @@ -409,8 +411,8 @@ impl TextPipeline {
self.update_buffer(
fonts,
text_spans,
layout.linebreak,
layout.justify,
linebreak,
justify,
MIN_WIDTH_CONTENT_BOUNDS,
scale_factor,
computed,
Expand Down Expand Up @@ -445,10 +447,10 @@ impl TextPipeline {
/// Render information for a corresponding text block.
///
/// Contains scaled glyphs and their size. Generated via [`TextPipeline::queue_text`] when an entity has
/// [`TextLayout`] and [`ComputedTextBlock`] components.
/// [`JustifyText`], [`LineBreak`] and [`TextBuffer`] components.
#[derive(Component, Clone, Default, Debug, Reflect)]
#[reflect(Component, Default, Debug, Clone)]
pub struct TextLayoutInfo {
pub struct ComputedTextLayout {
/// Scaled and positioned glyphs in screenspace
pub glyphs: Vec<PositionedGlyph>,
/// Rects bounding the text block's text sections.
Expand All @@ -458,7 +460,7 @@ pub struct TextLayoutInfo {
pub size: Vec2,
}

/// Size information for a corresponding [`ComputedTextBlock`] component.
/// Size information for a corresponding [`TextBuffer`] component.
///
/// Generated via [`TextPipeline::create_text_measure`].
#[derive(Debug)]
Expand All @@ -476,7 +478,7 @@ impl TextMeasureInfo {
pub fn compute_size(
&mut self,
bounds: TextBounds,
computed: &mut ComputedTextBlock,
computed: &mut TextBuffer,
font_system: &mut CosmicFontSystem,
) -> Vec2 {
// Note that this arbitrarily adjusts the buffer layout. We assume the buffer is always 'refreshed'
Expand Down
Loading