diff --git a/sugarloaf/src/components/rich_text/compositor.rs b/sugarloaf/src/components/rich_text/compositor.rs index e8b540e1c1..0964e08459 100644 --- a/sugarloaf/src/components/rich_text/compositor.rs +++ b/sugarloaf/src/components/rich_text/compositor.rs @@ -207,7 +207,7 @@ impl Compositor { self.batches.add_rect( &Rect::new( rect.x, - style.topline, + style.topline + style.padding_y, rect.width, style.line_height_without_mod, ), @@ -219,7 +219,7 @@ impl Compositor { self.batches.add_rect( &Rect::new( rect.x, - style.topline, + style.topline + style.padding_y, rect.width, style.line_height_without_mod, ), @@ -231,7 +231,7 @@ impl Compositor { self.batches.add_rect( &Rect::new( rect.x + 2.0, - style.topline + 2.0, + style.topline + style.padding_y + 2.0, rect.width - 4.0, style.line_height_without_mod - 4.0, ), diff --git a/sugarloaf/src/components/rich_text/mod.rs b/sugarloaf/src/components/rich_text/mod.rs index 6e4cf66d23..a207a38653 100644 --- a/sugarloaf/src/components/rich_text/mod.rs +++ b/sugarloaf/src/components/rich_text/mod.rs @@ -7,7 +7,7 @@ use crate::components::core::orthographic_projection; use crate::components::rich_text::image_cache::{GlyphCache, ImageCache}; use crate::context::Context; use crate::font::FontLibrary; -use crate::layout::SugarDimensions; +use crate::layout::{RichTextLayout, SugarDimensions}; use crate::sugarloaf::graphics::GraphicRenderRequest; use crate::Graphics; use compositor::{Compositor, DisplayList, Rect, Vertex}; @@ -277,8 +277,7 @@ impl RichTextBrush { &rt.lines, position, library, - &rt.layout.dimensions, - &rt.layout.line_height, + &rt.layout, graphics, ); } @@ -412,10 +411,11 @@ fn draw_layout( lines: &Vec, pos: (f32, f32), font_library: &FontLibrary, - rect: &SugarDimensions, - line_height_mod: &f32, + rte_layout: &RichTextLayout, graphics: &mut Graphics, ) { + let rect = &rte_layout.dimensions; + let line_height_mod = &rte_layout.line_height; // let start = std::time::Instant::now(); let (x, y) = pos; let (image_cache, glyphs_cache) = caches; @@ -458,6 +458,13 @@ fn draw_layout( let line_height_without_mod = ascent + descent + leading; let line_height = line_height_without_mod * line_height_mod; + // If line height is 10. and and modifier is 1.5, then 5 + let padding_y = if line_height_mod > &1. { + (line_height - line_height_without_mod) / 2. + } else { + 0. + }; + let py = line_y; for run in &line.render_data.runs { glyphs.clear(); @@ -467,7 +474,7 @@ fn draw_layout( let run_x = px; for glyph in &run.glyphs { let x = px; - let y = py; + let y = py + padding_y; px += rect.width * char_width; glyphs.push(Glyph { id: glyph.simple_data().0, @@ -483,6 +490,7 @@ fn draw_layout( background_color: run.span.background_color, baseline: py, topline: py - ascent, + padding_y, line_height, line_height_without_mod, advance: px - run_x, @@ -602,6 +610,7 @@ fn fetch_dimensions( cursor: run.span.cursor, background_color: None, baseline: py, + padding_y: 0., topline: py - ascent, line_height, line_height_without_mod: line_height, diff --git a/sugarloaf/src/components/rich_text/text.rs b/sugarloaf/src/components/rich_text/text.rs index 939f61dcc0..9d4f1c94a0 100644 --- a/sugarloaf/src/components/rich_text/text.rs +++ b/sugarloaf/src/components/rich_text/text.rs @@ -30,6 +30,8 @@ pub struct TextRunStyle<'a> { pub topline: f32, /// Absolute line height of the run. pub line_height: f32, + /// Padding y + pub padding_y: f32, /// Absolute line height of the run without mod. pub line_height_without_mod: f32, /// Total advance of the run.