From b2492d645e2c0a40d9ef215ba93687047e121525 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 10:53:59 +0100 Subject: [PATCH 1/9] Update `GlobalTransform` on insertion (#9081) # Objective `GlobalTransform` after insertion will be updated only on `Transform` or hierarchy change. Fixes #9075 ## Solution Update `GlobalTransform` after insertion too. --- ## Changelog - `GlobalTransform` is now updated not only on `Transform` or hierarchy change, but also on insertion. --- crates/bevy_transform/src/systems.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index 46629eca57db9..420ce7a9e3623 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -2,6 +2,7 @@ use crate::components::{GlobalTransform, Transform}; use bevy_ecs::{ change_detection::Ref, prelude::{Changed, DetectChanges, Entity, Query, With, Without}, + query::{Added, Or}, removal_detection::RemovedComponents, system::{Local, ParamSet}, }; @@ -14,7 +15,11 @@ pub fn sync_simple_transforms( mut query: ParamSet<( Query< (&Transform, &mut GlobalTransform), - (Changed, Without, Without), + ( + Or<(Changed, Added)>, + Without, + Without, + ), >, Query<(Ref, &mut GlobalTransform), Without>, )>, @@ -31,7 +36,7 @@ pub fn sync_simple_transforms( let mut query = query.p1(); let mut iter = query.iter_many_mut(orphaned.iter()); while let Some((transform, mut global_transform)) = iter.fetch_next() { - if !transform.is_changed() { + if !transform.is_changed() && !global_transform.is_added() { *global_transform = GlobalTransform::from(*transform); } } @@ -56,7 +61,7 @@ pub fn propagate_transforms( orphaned_entities.sort_unstable(); root_query.par_iter_mut().for_each_mut( |(entity, children, transform, mut global_transform)| { - let changed = transform.is_changed() || orphaned_entities.binary_search(&entity).is_ok(); + let changed = transform.is_changed() || global_transform.is_added() || orphaned_entities.binary_search(&entity).is_ok(); if changed { *global_transform = GlobalTransform::from(*transform); } @@ -143,7 +148,7 @@ unsafe fn propagate_recursive( return; }; - changed |= transform.is_changed(); + changed |= transform.is_changed() || global_transform.is_added(); if changed { *global_transform = parent.mul_transform(*transform); } From e40349d9ce0d0d51cf06efd1e6c3e68783fd117d Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 14:23:42 +0100 Subject: [PATCH 2/9] `TextPipeline::queue_text`, `TextMeasureInfo::compute_size_from_section_texts` and `GlyphBrush::process_glyphs` each have a section of code that calculates the minimum bounds around a list of text sections. The first two functions don't apply any rounding, but `process_glyphs` also floors all the values. It seems like this can cause conflicts where the text gets incorrectly shaped. Also when Bevy computes the text bounds it chooses the smallest possible rect that fits all the glyphs, ignoring white space. The glyphs are then realigned vertically so the first glyph is on the top line. Leading empty lines are missed off. This PR adds a function `compute_text_bounds` that replaces the duplicate code, so the text bounds are rounded the same way by each function. Also, since Bevy doen't use ab_glyph to control vertical alignment, the min y bound is just always set to 0 which ensures no leading empty lines will be will missed. There is another problem in that trailing empty lines are also ignored, but that's more difficult to deal with and much less important than the other issues. --- crates/bevy_text/src/glyph_brush.rs | 53 ++++++++++++++++++----------- crates/bevy_text/src/pipeline.rs | 45 ++++-------------------- 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 9b17f09a7b910..d6d97a1496ce7 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -1,6 +1,6 @@ -use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _}; +use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _, PxScaleFont}; use bevy_asset::{Assets, Handle}; -use bevy_math::Vec2; +use bevy_math::{Vec2, Rect}; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_utils::tracing::warn; @@ -11,7 +11,7 @@ use glyph_brush_layout::{ use crate::{ error::TextError, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, - TextAlignment, TextSettings, YAxisOrientation, + TextAlignment, TextSettings, YAxisOrientation, text, }; pub struct GlyphBrush { @@ -84,20 +84,7 @@ impl GlyphBrush { }) .collect::, _>>()?; - let mut min_x = std::f32::MAX; - let mut min_y = std::f32::MAX; - let mut max_y = std::f32::MIN; - for sg in &glyphs { - let glyph = &sg.glyph; - - let scaled_font = sections_data[sg.section_index].3; - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - min_x = min_x.floor(); - min_y = min_y.floor(); - max_y = max_y.floor(); + let text_bounds = compute_text_bounds(&glyphs, |index| §ions_data[index].3); let mut positioned_glyphs = Vec::new(); for sg in glyphs { @@ -136,11 +123,11 @@ impl GlyphBrush { let glyph_rect = texture_atlas.textures[atlas_info.glyph_index]; let size = Vec2::new(glyph_rect.width(), glyph_rect.height()); - let x = bounds.min.x + size.x / 2.0 - min_x; + let x = bounds.min.x + size.x / 2.0 - text_bounds.min.x; let y = match y_axis_orientation { - YAxisOrientation::BottomToTop => max_y - bounds.max.y + size.y / 2.0, - YAxisOrientation::TopToBottom => bounds.min.y + size.y / 2.0 - min_y, + YAxisOrientation::BottomToTop => text_bounds.max.y - bounds.max.y + size.y / 2.0, + YAxisOrientation::TopToBottom => bounds.min.y + size.y / 2.0 - text_bounds.min.y, }; let position = adjust.position(Vec2::new(x, y)); @@ -209,3 +196,29 @@ impl GlyphPlacementAdjuster { Vec2::new(self.0, 0.) + v } } + +pub fn compute_text_bounds<'a, T>( + section_glyphs: &[SectionGlyph], + get_scaled_font: impl Fn(usize) -> &'a PxScaleFont, +) -> bevy_math::Rect +where + T: ab_glyph::Font + 'a, +{ + let mut text_bounds = Rect { + min: Vec2::splat(std::f32::MAX), + max: Vec2::splat(std::f32::MIN), + }; + + for sg in section_glyphs { + let scaled_font = get_scaled_font(sg.section_index); + let glyph = &sg.glyph; + text_bounds = text_bounds.union(Rect { + min: Vec2::new(glyph.position.x, 0.), + max: Vec2::new(glyph.position.x + scaled_font.h_advance(glyph.id), glyph.position.y - scaled_font.descent()) + }); + } + + text_bounds.min = text_bounds.min.floor(); + text_bounds.max = text_bounds.max.ceil(); + text_bounds +} \ No newline at end of file diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index e71e49c030e67..2d16ce03c3356 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -1,4 +1,4 @@ -use ab_glyph::{PxScale, ScaleFont}; +use ab_glyph::PxScale; use bevy_asset::{Assets, Handle, HandleId}; use bevy_ecs::component::Component; use bevy_ecs::system::Resource; @@ -10,8 +10,9 @@ use bevy_utils::HashMap; use glyph_brush_layout::{FontId, GlyphPositioner, SectionGeometry, SectionText}; use crate::{ - error::TextError, glyph_brush::GlyphBrush, scale_value, BreakLineOn, Font, FontAtlasSet, - FontAtlasWarning, PositionedGlyph, TextAlignment, TextSection, TextSettings, YAxisOrientation, + compute_text_bounds, error::TextError, glyph_brush::GlyphBrush, scale_value, BreakLineOn, Font, + FontAtlasSet, FontAtlasWarning, PositionedGlyph, TextAlignment, TextSection, TextSettings, + YAxisOrientation, }; #[derive(Default, Resource)] @@ -84,24 +85,7 @@ impl TextPipeline { return Ok(TextLayoutInfo::default()); } - let mut min_x: f32 = std::f32::MAX; - let mut min_y: f32 = std::f32::MAX; - let mut max_x: f32 = std::f32::MIN; - let mut max_y: f32 = std::f32::MIN; - - for sg in §ion_glyphs { - let scaled_font = scaled_fonts[sg.section_index]; - let glyph = &sg.glyph; - // The fonts use a coordinate system increasing upwards so ascent is a positive value - // and descent is negative, but Bevy UI uses a downwards increasing coordinate system, - // so we have to subtract from the baseline position to get the minimum and maximum values. - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_x = max_x.max(glyph.position.x + scaled_font.h_advance(glyph.id)); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - - let size = Vec2::new(max_x - min_x, max_y - min_y); + let size = compute_text_bounds(§ion_glyphs, |index| &scaled_fonts[index]).size(); let glyphs = self.brush.process_glyphs( section_glyphs, @@ -229,24 +213,7 @@ impl TextMeasureInfo { .line_breaker(self.linebreak_behaviour) .calculate_glyphs(&self.fonts, &geom, sections); - let mut min_x: f32 = std::f32::MAX; - let mut min_y: f32 = std::f32::MAX; - let mut max_x: f32 = std::f32::MIN; - let mut max_y: f32 = std::f32::MIN; - - for sg in section_glyphs { - let scaled_font = &self.scaled_fonts[sg.section_index]; - let glyph = &sg.glyph; - // The fonts use a coordinate system increasing upwards so ascent is a positive value - // and descent is negative, but Bevy UI uses a downwards increasing coordinate system, - // so we have to subtract from the baseline position to get the minimum and maximum values. - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_x = max_x.max(glyph.position.x + scaled_font.h_advance(glyph.id)); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - - Vec2::new(max_x - min_x, max_y - min_y) + compute_text_bounds(§ion_glyphs, |index| &self.scaled_fonts[index]).size() } pub fn compute_size(&self, bounds: Vec2) -> Vec2 { From bb4229ec46265162f8ad7ae5b43429b8362e99bb Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 14:27:58 +0100 Subject: [PATCH 3/9] `TextPipeline::queue_text`, `TextMeasureInfo::compute_size_from_section_texts` and `GlyphBrush::process_glyphs` each have a section of code that calculates the minimum bounds around a list of text sections. The first two functions don't apply any rounding, but `process_glyphs` also floors all the values. It seems like this can cause conflicts where the text gets incorrectly shaped. Also when Bevy computes the text bounds it chooses the smallest possible rect that fits all the glyphs, ignoring white space. The glyphs are then realigned vertically so the first glyph is on the top line. Leading empty lines are missed off. This PR adds a function `compute_text_bounds` that replaces the duplicate code, so the text bounds are rounded the same way by each function. Also, since Bevy doen't use ab_glyph to control vertical alignment, the min y bound is just always set to 0 which ensures no leading empty lines will be will missed. There is another problem in that trailing empty lines are also ignored, but that's more difficult to deal with and much less important than the other issues. --- crates/bevy_text/src/glyph_brush.rs | 53 ++++++++++++++++++----------- crates/bevy_text/src/pipeline.rs | 45 ++++-------------------- 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 9b17f09a7b910..d6d97a1496ce7 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -1,6 +1,6 @@ -use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _}; +use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _, PxScaleFont}; use bevy_asset::{Assets, Handle}; -use bevy_math::Vec2; +use bevy_math::{Vec2, Rect}; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_utils::tracing::warn; @@ -11,7 +11,7 @@ use glyph_brush_layout::{ use crate::{ error::TextError, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, - TextAlignment, TextSettings, YAxisOrientation, + TextAlignment, TextSettings, YAxisOrientation, text, }; pub struct GlyphBrush { @@ -84,20 +84,7 @@ impl GlyphBrush { }) .collect::, _>>()?; - let mut min_x = std::f32::MAX; - let mut min_y = std::f32::MAX; - let mut max_y = std::f32::MIN; - for sg in &glyphs { - let glyph = &sg.glyph; - - let scaled_font = sections_data[sg.section_index].3; - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - min_x = min_x.floor(); - min_y = min_y.floor(); - max_y = max_y.floor(); + let text_bounds = compute_text_bounds(&glyphs, |index| §ions_data[index].3); let mut positioned_glyphs = Vec::new(); for sg in glyphs { @@ -136,11 +123,11 @@ impl GlyphBrush { let glyph_rect = texture_atlas.textures[atlas_info.glyph_index]; let size = Vec2::new(glyph_rect.width(), glyph_rect.height()); - let x = bounds.min.x + size.x / 2.0 - min_x; + let x = bounds.min.x + size.x / 2.0 - text_bounds.min.x; let y = match y_axis_orientation { - YAxisOrientation::BottomToTop => max_y - bounds.max.y + size.y / 2.0, - YAxisOrientation::TopToBottom => bounds.min.y + size.y / 2.0 - min_y, + YAxisOrientation::BottomToTop => text_bounds.max.y - bounds.max.y + size.y / 2.0, + YAxisOrientation::TopToBottom => bounds.min.y + size.y / 2.0 - text_bounds.min.y, }; let position = adjust.position(Vec2::new(x, y)); @@ -209,3 +196,29 @@ impl GlyphPlacementAdjuster { Vec2::new(self.0, 0.) + v } } + +pub fn compute_text_bounds<'a, T>( + section_glyphs: &[SectionGlyph], + get_scaled_font: impl Fn(usize) -> &'a PxScaleFont, +) -> bevy_math::Rect +where + T: ab_glyph::Font + 'a, +{ + let mut text_bounds = Rect { + min: Vec2::splat(std::f32::MAX), + max: Vec2::splat(std::f32::MIN), + }; + + for sg in section_glyphs { + let scaled_font = get_scaled_font(sg.section_index); + let glyph = &sg.glyph; + text_bounds = text_bounds.union(Rect { + min: Vec2::new(glyph.position.x, 0.), + max: Vec2::new(glyph.position.x + scaled_font.h_advance(glyph.id), glyph.position.y - scaled_font.descent()) + }); + } + + text_bounds.min = text_bounds.min.floor(); + text_bounds.max = text_bounds.max.ceil(); + text_bounds +} \ No newline at end of file diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index e71e49c030e67..2d16ce03c3356 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -1,4 +1,4 @@ -use ab_glyph::{PxScale, ScaleFont}; +use ab_glyph::PxScale; use bevy_asset::{Assets, Handle, HandleId}; use bevy_ecs::component::Component; use bevy_ecs::system::Resource; @@ -10,8 +10,9 @@ use bevy_utils::HashMap; use glyph_brush_layout::{FontId, GlyphPositioner, SectionGeometry, SectionText}; use crate::{ - error::TextError, glyph_brush::GlyphBrush, scale_value, BreakLineOn, Font, FontAtlasSet, - FontAtlasWarning, PositionedGlyph, TextAlignment, TextSection, TextSettings, YAxisOrientation, + compute_text_bounds, error::TextError, glyph_brush::GlyphBrush, scale_value, BreakLineOn, Font, + FontAtlasSet, FontAtlasWarning, PositionedGlyph, TextAlignment, TextSection, TextSettings, + YAxisOrientation, }; #[derive(Default, Resource)] @@ -84,24 +85,7 @@ impl TextPipeline { return Ok(TextLayoutInfo::default()); } - let mut min_x: f32 = std::f32::MAX; - let mut min_y: f32 = std::f32::MAX; - let mut max_x: f32 = std::f32::MIN; - let mut max_y: f32 = std::f32::MIN; - - for sg in §ion_glyphs { - let scaled_font = scaled_fonts[sg.section_index]; - let glyph = &sg.glyph; - // The fonts use a coordinate system increasing upwards so ascent is a positive value - // and descent is negative, but Bevy UI uses a downwards increasing coordinate system, - // so we have to subtract from the baseline position to get the minimum and maximum values. - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_x = max_x.max(glyph.position.x + scaled_font.h_advance(glyph.id)); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - - let size = Vec2::new(max_x - min_x, max_y - min_y); + let size = compute_text_bounds(§ion_glyphs, |index| &scaled_fonts[index]).size(); let glyphs = self.brush.process_glyphs( section_glyphs, @@ -229,24 +213,7 @@ impl TextMeasureInfo { .line_breaker(self.linebreak_behaviour) .calculate_glyphs(&self.fonts, &geom, sections); - let mut min_x: f32 = std::f32::MAX; - let mut min_y: f32 = std::f32::MAX; - let mut max_x: f32 = std::f32::MIN; - let mut max_y: f32 = std::f32::MIN; - - for sg in section_glyphs { - let scaled_font = &self.scaled_fonts[sg.section_index]; - let glyph = &sg.glyph; - // The fonts use a coordinate system increasing upwards so ascent is a positive value - // and descent is negative, but Bevy UI uses a downwards increasing coordinate system, - // so we have to subtract from the baseline position to get the minimum and maximum values. - min_x = min_x.min(glyph.position.x); - min_y = min_y.min(glyph.position.y - scaled_font.ascent()); - max_x = max_x.max(glyph.position.x + scaled_font.h_advance(glyph.id)); - max_y = max_y.max(glyph.position.y - scaled_font.descent()); - } - - Vec2::new(max_x - min_x, max_y - min_y) + compute_text_bounds(§ion_glyphs, |index| &self.scaled_fonts[index]).size() } pub fn compute_size(&self, bounds: Vec2) -> Vec2 { From f7cca693a3cc2d08e021ea40a6fb091ceda6ce62 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 14:30:40 +0100 Subject: [PATCH 4/9] fmt --- crates/bevy_text/src/glyph_brush.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index d6d97a1496ce7..d1891c5938ed7 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -1,6 +1,6 @@ -use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _, PxScaleFont}; +use ab_glyph::{Font as _, FontArc, Glyph, PxScaleFont, ScaleFont as _}; use bevy_asset::{Assets, Handle}; -use bevy_math::{Vec2, Rect}; +use bevy_math::{Rect, Vec2}; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_utils::tracing::warn; @@ -10,8 +10,8 @@ use glyph_brush_layout::{ }; use crate::{ - error::TextError, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, - TextAlignment, TextSettings, YAxisOrientation, text, + error::TextError, text, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, + TextAlignment, TextSettings, YAxisOrientation, }; pub struct GlyphBrush { @@ -126,8 +126,12 @@ impl GlyphBrush { let x = bounds.min.x + size.x / 2.0 - text_bounds.min.x; let y = match y_axis_orientation { - YAxisOrientation::BottomToTop => text_bounds.max.y - bounds.max.y + size.y / 2.0, - YAxisOrientation::TopToBottom => bounds.min.y + size.y / 2.0 - text_bounds.min.y, + YAxisOrientation::BottomToTop => { + text_bounds.max.y - bounds.max.y + size.y / 2.0 + } + YAxisOrientation::TopToBottom => { + bounds.min.y + size.y / 2.0 - text_bounds.min.y + } }; let position = adjust.position(Vec2::new(x, y)); @@ -214,11 +218,14 @@ where let glyph = &sg.glyph; text_bounds = text_bounds.union(Rect { min: Vec2::new(glyph.position.x, 0.), - max: Vec2::new(glyph.position.x + scaled_font.h_advance(glyph.id), glyph.position.y - scaled_font.descent()) + max: Vec2::new( + glyph.position.x + scaled_font.h_advance(glyph.id), + glyph.position.y - scaled_font.descent(), + ), }); } - + text_bounds.min = text_bounds.min.floor(); text_bounds.max = text_bounds.max.ceil(); text_bounds -} \ No newline at end of file +} From 2b33ecb8423476f05b5ae5041fa5360c7d46fa17 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 14:32:25 +0100 Subject: [PATCH 5/9] Removed an unused import --- crates/bevy_text/src/glyph_brush.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index d1891c5938ed7..668d0297b937f 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -10,7 +10,7 @@ use glyph_brush_layout::{ }; use crate::{ - error::TextError, text, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, + error::TextError, BreakLineOn, Font, FontAtlasSet, FontAtlasWarning, GlyphAtlasInfo, TextAlignment, TextSettings, YAxisOrientation, }; From dcaf0c9d58f24df583c659e796c1674eff8ec402 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 12 Jul 2023 15:50:59 +0100 Subject: [PATCH 6/9] removed unneeded rounding --- crates/bevy_text/src/glyph_brush.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index bce95d28a6247..2b06e942a6126 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -1,6 +1,6 @@ -use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _, PxScaleFont}; +use ab_glyph::{Font as _, FontArc, Glyph, PxScaleFont, ScaleFont as _}; use bevy_asset::{Assets, Handle}; -use bevy_math::{Vec2, Rect}; +use bevy_math::{Rect, Vec2}; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_utils::tracing::warn; @@ -225,7 +225,5 @@ where }); } - text_bounds.min = text_bounds.min.floor(); - text_bounds.max = text_bounds.max.ceil(); text_bounds } From 0ed18d8d2ac5aa6180ab8b864f9bebfb7a08828a Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 13 Jul 2023 12:11:12 +0100 Subject: [PATCH 7/9] Changed the visibility of `bevy_ui::glyph_brush::compute_text_bounds` to `pub (crate)` and added some doc comments. --- crates/bevy_text/src/glyph_brush.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 2b06e942a6126..7d222b06bb98d 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -201,7 +201,9 @@ impl GlyphPlacementAdjuster { } } -pub fn compute_text_bounds<'a, T>( +/// Computes the bounds containing a block of text. +/// Ignores empty trailing lines. +pub (crate) fn compute_text_bounds<'a, T>( section_glyphs: &[SectionGlyph], get_scaled_font: impl Fn(usize) -> &'a PxScaleFont, ) -> bevy_math::Rect From 01f67884ab25fb2cb1c174c46672d31ad3bb81e3 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 13 Jul 2023 12:13:35 +0100 Subject: [PATCH 8/9] cargo fmt --- crates/bevy_text/src/glyph_brush.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 7d222b06bb98d..d94c1f7907c92 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -203,7 +203,7 @@ impl GlyphPlacementAdjuster { /// Computes the bounds containing a block of text. /// Ignores empty trailing lines. -pub (crate) fn compute_text_bounds<'a, T>( +pub(crate) fn compute_text_bounds<'a, T>( section_glyphs: &[SectionGlyph], get_scaled_font: impl Fn(usize) -> &'a PxScaleFont, ) -> bevy_math::Rect From 93011f595fb153597448444ecfd0758163abebb8 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 13 Jul 2023 12:17:13 +0100 Subject: [PATCH 9/9] improved comment --- crates/bevy_text/src/glyph_brush.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index d94c1f7907c92..70fea30322e18 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -201,7 +201,7 @@ impl GlyphPlacementAdjuster { } } -/// Computes the bounds containing a block of text. +/// Computes the minimal bounding rectangle for a block of text. /// Ignores empty trailing lines. pub(crate) fn compute_text_bounds<'a, T>( section_glyphs: &[SectionGlyph],