diff --git a/sugarloaf/examples/line_height.rs b/sugarloaf/examples/line_height.rs index f678fbc08..cda250801 100644 --- a/sugarloaf/examples/line_height.rs +++ b/sugarloaf/examples/line_height.rs @@ -188,7 +188,7 @@ impl ApplicationHandler for Application { "?", FragmentStyle { color: [0.5, 0.5, 1.0, 1.0], - background_color: Some([1.0, 1.0, 1.0, 1.0]), + background_color: Some([1.0, 0.5, 1.0, 1.0]), cursor: Some(SugarCursor::Block([1.0, 1.0, 1.0, 1.0])), ..FragmentStyle::default() }, diff --git a/sugarloaf/src/components/rich_text/compositor.rs b/sugarloaf/src/components/rich_text/compositor.rs index 51d9de855..e8b540e1c 100644 --- a/sugarloaf/src/components/rich_text/compositor.rs +++ b/sugarloaf/src/components/rich_text/compositor.rs @@ -151,7 +151,7 @@ impl Compositor { }), Some(FragmentStyleDecoration::Strikethrough) => Some(RunUnderline { enabled: true, - offset: (style.line_height / 3.5).round() as i32, + offset: (style.line_height_without_mod / 3.5).round() as i32, size: 2.0, color: style.decoration_color.unwrap_or(style.color), is_doubled: false, @@ -205,14 +205,24 @@ impl Compositor { match style.cursor { Some(SugarCursor::Block(cursor_color)) => { self.batches.add_rect( - &Rect::new(rect.x, style.topline, rect.width, style.line_height), + &Rect::new( + rect.x, + style.topline, + rect.width, + style.line_height_without_mod, + ), depth, &cursor_color, ); } Some(SugarCursor::HollowBlock(cursor_color)) => { self.batches.add_rect( - &Rect::new(rect.x, style.topline, rect.width, style.line_height), + &Rect::new( + rect.x, + style.topline, + rect.width, + style.line_height_without_mod, + ), depth, &cursor_color, ); @@ -223,7 +233,7 @@ impl Compositor { rect.x + 2.0, style.topline + 2.0, rect.width - 4.0, - style.line_height - 4.0, + style.line_height_without_mod - 4.0, ), depth, &bg_color, @@ -232,7 +242,7 @@ impl Compositor { } Some(SugarCursor::Caret(cursor_color)) => { self.batches.add_rect( - &Rect::new(rect.x, style.topline, 3.0, style.line_height), + &Rect::new(rect.x, style.topline, 3.0, style.line_height_without_mod), depth, &cursor_color, ); @@ -247,7 +257,7 @@ impl Compositor { rect.width, style.baseline, depth, - style.line_height, + style.line_height_without_mod, ); } diff --git a/sugarloaf/src/components/rich_text/mod.rs b/sugarloaf/src/components/rich_text/mod.rs index e24b87875..6e4cf66d2 100644 --- a/sugarloaf/src/components/rich_text/mod.rs +++ b/sugarloaf/src/components/rich_text/mod.rs @@ -413,7 +413,7 @@ fn draw_layout( pos: (f32, f32), font_library: &FontLibrary, rect: &SugarDimensions, - custom_line_height: &f32, + line_height_mod: &f32, graphics: &mut Graphics, ) { // let start = std::time::Instant::now(); @@ -455,11 +455,10 @@ fn draw_layout( let mut px = x + 0.0; let baseline = line_y + ascent; line_y = baseline + descent; - // line_y = line_y; + let line_height_without_mod = ascent + descent + leading; + let line_height = line_height_without_mod * line_height_mod; + let py = line_y; - let line_height_calc = ascent + descent + leading; - let line_height = line_height_calc * custom_line_height; - // let line_height = rect.height * line_height; for run in &line.render_data.runs { glyphs.clear(); let font = run.span.font_id; @@ -485,6 +484,7 @@ fn draw_layout( baseline: py, topline: py - ascent, line_height, + line_height_without_mod, advance: px - run_x, decoration: run.span.decoration, decoration_color: run.span.decoration_color, @@ -528,10 +528,9 @@ fn draw_layout( ); } - if custom_line_height > &1.0 { - line_y += line_height - line_height_calc; + if line_height_mod > &1.0 { + line_y += line_height - line_height_without_mod; } - // line_y += line_height; } // let duration = start.elapsed(); @@ -605,6 +604,7 @@ fn fetch_dimensions( baseline: py, topline: py - ascent, line_height, + line_height_without_mod: line_height, advance: px - run_x, decoration: None, decoration_color: None, diff --git a/sugarloaf/src/components/rich_text/text.rs b/sugarloaf/src/components/rich_text/text.rs index 5eb5521c7..939f61dcc 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, + /// Absolute line height of the run without mod. + pub line_height_without_mod: f32, /// Total advance of the run. pub advance: f32, /// Underline style.