Skip to content

Commit

Permalink
update example to line_height
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Dec 18, 2024
1 parent 93b33ff commit a41e691
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rio_window::{
use std::error::Error;
use sugarloaf::{
layout::RootStyle, FragmentStyle, FragmentStyleDecoration, Object, RichText,
Sugarloaf, SugarloafWindow, SugarloafWindowSize, UnderlineInfo, UnderlineShape,
Sugarloaf, SugarCursor, SugarloafWindow, SugarloafWindowSize, UnderlineInfo, UnderlineShape,
};

fn main() {
Expand Down Expand Up @@ -267,6 +267,15 @@ impl ApplicationHandler for Application {
..FragmentStyle::default()
},
)
.add_text(
"?",
FragmentStyle {
color: [0.5, 0.5, 1.0, 1.0],
background_color: Some([1.0, 1.0, 1.0, 1.0]),
cursor: Some(SugarCursor::Block([1.0, 1.0, 1.0, 1.0])),
..FragmentStyle::default()
},
)
.build();

sugarloaf.set_objects(vec![Object::RichText(RichText {
Expand Down
4 changes: 2 additions & 2 deletions sugarloaf/src/components/rich_text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn draw_layout(
}

let first_run = &line.render_data.runs[0];
// let ascent = first_run.ascent.round();
let ascent = first_run.ascent.round();
// let descent = first_run.descent.round();
// let leading = (first_run.leading).round() * 2.;
let mut px = x + 0.0;
Expand Down Expand Up @@ -480,7 +480,7 @@ fn draw_layout(
cursor: run.span.cursor,
background_color: run.span.background_color,
baseline: py,
topline: py - rect.height,
topline: py - ascent,
line_height,
advance: px - run_x,
decoration: run.span.decoration,
Expand Down
2 changes: 1 addition & 1 deletion sugarloaf/src/layout/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Content {
let render_data = content.get_state(&id).unwrap().lines[0].clone();

if let Some(dimension) = advance_brush.dimensions(&self.fonts, &render_data) {
rte.layout.dimensions.height = dimension.height;
rte.layout.dimensions.height = dimension.height * rte.layout.line_height;
rte.layout.dimensions.width = dimension.width;
}
}
Expand Down

0 comments on commit a41e691

Please sign in to comment.