Skip to main content

line_metrics/
line_metrics.rs

1use impellers::*;
2mod common;
3
4fn main() {
5    let framework = common::SdlGlImpellerFrameWork::new();
6    // if you want to do any initialization before event loop,
7    // this is the place for that.
8    let mut paint = Paint::default(); // paint object to reuse
9    let paragraph = {
10        let ttx = TypographyContext::default(); // register any custom fonts if you want
11        let mut puilder = ParagraphBuilder::new(&ttx).unwrap();
12        let mut pstyle = ParagraphStyle::default();
13        // you can set a custom font family if you want, but lets just use the system fonts
14        pstyle.set_font_size(48.0);
15        pstyle.set_font_weight(FontWeight::ExtraBold);
16        paint.set_color(Color::BLUEBERRY);
17        pstyle.set_foreground(&paint);
18        puilder.push_style(&pstyle);
19        puilder.add_text("HELLO EVERYONE");
20        puilder.build(600.0).unwrap()
21    };
22    let metrics = paragraph.get_line_metrics().unwrap();
23    dbg!(metrics.get_width(0));
24    dbg!(metrics.get_height(0));
25    dbg!(metrics.get_ascent(0));
26    dbg!(metrics.get_descent(0));
27    dbg!(metrics.get_baseline(0));
28    dbg!(metrics.get_left(0));
29    dbg!(metrics.get_unscaled_ascent(0));
30    dbg!(metrics.get_code_unit_start_index_utf16(0));
31
32    let dl = {
33        let mut builder = DisplayListBuilder::new(None);
34        paint.set_color(Color::BLACK); // clear with black first
35        builder.draw_paint(&paint);
36        builder.draw_paragraph(&paragraph, Point::new(100.0, 100.0));
37        builder.build().unwrap()
38    };
39    framework.enter_event_loop(Some(dl), None);
40}