iced-yoda/wgpu/src/renderer/widget/text.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2019-10-05 19:22:51 +02:00
use crate::{Primitive, Renderer};
use iced_native::{
text, Color, Font, HorizontalAlignment, MouseCursor, Rectangle, Size,
VerticalAlignment,
};
2019-10-05 19:22:51 +02:00
use std::f32;
2019-11-06 02:47:01 +01:00
// TODO: Obtain from renderer configuration
const DEFAULT_TEXT_SIZE: f32 = 20.0;
2019-11-04 02:10:39 +01:00
2019-10-05 19:22:51 +02:00
impl text::Renderer for Renderer {
fn default_size(&self) -> u16 {
DEFAULT_TEXT_SIZE as u16
}
fn measure(
&self,
content: &str,
size: u16,
font: Font,
bounds: Size,
) -> (f32, f32) {
self.text_pipeline
.measure(content, f32::from(size), font, bounds)
2019-10-05 19:22:51 +02:00
}
fn draw(
&mut self,
bounds: Rectangle,
content: &str,
size: u16,
font: Font,
color: Option<Color>,
horizontal_alignment: HorizontalAlignment,
vertical_alignment: VerticalAlignment,
) -> Self::Output {
2019-10-11 23:30:53 +02:00
(
Primitive::Text {
content: content.to_string(),
size: f32::from(size),
bounds,
color: color.unwrap_or(Color::BLACK),
font,
horizontal_alignment,
vertical_alignment,
2019-10-11 23:30:53 +02:00
},
MouseCursor::OutOfBounds,
)
2019-10-05 19:22:51 +02:00
}
}