From 5a84709e4e904b83c6130d744a1dafcc205fe26b Mon Sep 17 00:00:00 2001 From: tigregalis Date: Sat, 24 Oct 2020 22:53:06 +0800 Subject: [PATCH 1/4] fix wavy text --- crates/bevy_text/src/draw.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index e09410b6642b1..22ba330cd7e93 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -79,6 +79,7 @@ impl<'a> Drawable for DrawableText<'a> { let font = &self.font.font; let scale = PxScale::from(self.style.font_size); let scaled_font = ab_glyph::Font::as_scaled(&font, scale); + let offset = (scaled_font.ascent() + scaled_font.descent()) / 2.0; let mut caret = self.position; let mut last_glyph: Option = None; @@ -119,12 +120,11 @@ impl<'a> Drawable for DrawableText<'a> { )?; let bounds = outlined.px_bounds(); - let offset = scaled_font.descent() + glyph_height; let transform = Mat4::from_translation( caret + Vec3::new( - 0.0 + glyph_width / 2.0 + bounds.min.x, - glyph_height / 2.0 - bounds.min.y - offset, + glyph_width / 2.0 + bounds.min.x, + glyph_height / 2.0 - bounds.max.y + offset, 0.0, ), ); From b03c0c9c60250849eaf566a88b20d593e0f77e0a Mon Sep 17 00:00:00 2001 From: tigregalis Date: Mon, 26 Oct 2020 08:25:39 +0800 Subject: [PATCH 2/4] corrected assumption with `offset` --- crates/bevy_text/src/draw.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index 22ba330cd7e93..dac2749674d88 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -79,7 +79,6 @@ impl<'a> Drawable for DrawableText<'a> { let font = &self.font.font; let scale = PxScale::from(self.style.font_size); let scaled_font = ab_glyph::Font::as_scaled(&font, scale); - let offset = (scaled_font.ascent() + scaled_font.descent()) / 2.0; let mut caret = self.position; let mut last_glyph: Option = None; @@ -120,11 +119,14 @@ impl<'a> Drawable for DrawableText<'a> { )?; let bounds = outlined.px_bounds(); + let x = bounds.min.x + glyph_width / 2.0; + // the 0.5 accounts for odd-numbered heights (bump up by 1 pixel) + let y = -bounds.max.y + glyph_height / 2.0 + 0.5; let transform = Mat4::from_translation( caret + Vec3::new( - glyph_width / 2.0 + bounds.min.x, - glyph_height / 2.0 - bounds.max.y + offset, + x, + y, 0.0, ), ); From ff365fd83479e5ee0207f97098bd30d39d3441ef Mon Sep 17 00:00:00 2001 From: tigregalis Date: Mon, 26 Oct 2020 08:30:06 +0800 Subject: [PATCH 3/4] format --- crates/bevy_text/src/draw.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index dac2749674d88..c026e86ec0d9b 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -122,14 +122,7 @@ impl<'a> Drawable for DrawableText<'a> { let x = bounds.min.x + glyph_width / 2.0; // the 0.5 accounts for odd-numbered heights (bump up by 1 pixel) let y = -bounds.max.y + glyph_height / 2.0 + 0.5; - let transform = Mat4::from_translation( - caret - + Vec3::new( - x, - y, - 0.0, - ), - ); + let transform = Mat4::from_translation(caret + Vec3::new(x, y, 0.0)); let sprite = TextureAtlasSprite { index: glyph_atlas_info.char_index, color: self.style.color, From 4a3937fedc77f4cbf45337894b1e2e76413d643c Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Fri, 30 Oct 2020 16:00:48 -0700 Subject: [PATCH 4/4] Update crates/bevy_text/src/draw.rs --- crates/bevy_text/src/draw.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index c026e86ec0d9b..b88718952ed07 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -121,7 +121,7 @@ impl<'a> Drawable for DrawableText<'a> { let bounds = outlined.px_bounds(); let x = bounds.min.x + glyph_width / 2.0; // the 0.5 accounts for odd-numbered heights (bump up by 1 pixel) - let y = -bounds.max.y + glyph_height / 2.0 + 0.5; + let y = -bounds.max.y + glyph_height / 2.0 - scaled_font.descent() + 0.5; let transform = Mat4::from_translation(caret + Vec3::new(x, y, 0.0)); let sprite = TextureAtlasSprite { index: glyph_atlas_info.char_index,