summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/text.rs
blob: 33e549cd40002f6991a8c964dc9e75aeac0ce55d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::{Primitive, Renderer};
use iced_native::{
    text, Color, Font, HorizontalAlignment, MouseCursor, Rectangle, Size,
    VerticalAlignment,
};

use std::f32;

impl text::Renderer for Renderer {
    const DEFAULT_SIZE: u16 = 20;

    fn measure(
        &self,
        content: &str,
        size: u16,
        font: Font,
        bounds: Size,
    ) -> (f32, f32) {
        self.text_pipeline
            .measure(content, f32::from(size), font, bounds)
    }

    fn draw(
        &mut self,
        defaults: &Self::Defaults,
        bounds: Rectangle,
        content: &str,
        size: u16,
        font: Font,
        color: Option<Color>,
        horizontal_alignment: HorizontalAlignment,
        vertical_alignment: VerticalAlignment,
    ) -> Self::Output {
        (
            Primitive::Text {
                content: content.to_string(),
                size: f32::from(size),
                bounds,
                color: color.unwrap_or(defaults.text.color),
                font,
                horizontal_alignment,
                vertical_alignment,
            },
            MouseCursor::OutOfBounds,
        )
    }
}