2020-05-19 17:15:44 +02:00
|
|
|
//! Write some text for your users to read.
|
2020-05-19 21:00:40 +02:00
|
|
|
use crate::backend::{self, Backend};
|
2021-10-14 16:07:22 +07:00
|
|
|
use crate::Renderer;
|
2020-05-19 21:00:40 +02:00
|
|
|
use iced_native::text;
|
2021-10-14 16:07:22 +07:00
|
|
|
use iced_native::{Font, Point, Size};
|
2020-05-19 17:15:44 +02:00
|
|
|
|
|
|
|
|
/// A paragraph of text.
|
|
|
|
|
///
|
|
|
|
|
/// This is an alias of an `iced_native` text with an `iced_wgpu::Renderer`.
|
|
|
|
|
pub type Text<Backend> = iced_native::Text<Renderer<Backend>>;
|
2020-05-19 21:00:40 +02:00
|
|
|
|
|
|
|
|
use std::f32;
|
|
|
|
|
|
|
|
|
|
impl<B> text::Renderer for Renderer<B>
|
|
|
|
|
where
|
|
|
|
|
B: Backend + backend::Text,
|
|
|
|
|
{
|
2020-06-19 00:08:28 +02:00
|
|
|
fn default_size(&self) -> u16 {
|
|
|
|
|
self.backend().default_size()
|
|
|
|
|
}
|
2020-05-19 21:00:40 +02:00
|
|
|
|
|
|
|
|
fn measure(
|
|
|
|
|
&self,
|
|
|
|
|
content: &str,
|
|
|
|
|
size: u16,
|
|
|
|
|
font: Font,
|
|
|
|
|
bounds: Size,
|
|
|
|
|
) -> (f32, f32) {
|
|
|
|
|
self.backend()
|
|
|
|
|
.measure(content, f32::from(size), font, bounds)
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 10:31:26 -07:00
|
|
|
fn hit_test(
|
|
|
|
|
&self,
|
|
|
|
|
content: &str,
|
|
|
|
|
size: f32,
|
|
|
|
|
font: Font,
|
|
|
|
|
bounds: Size,
|
|
|
|
|
point: Point,
|
|
|
|
|
nearest_only: bool,
|
2021-09-15 14:49:13 +07:00
|
|
|
) -> Option<text::Hit> {
|
2021-08-21 10:31:26 -07:00
|
|
|
self.backend().hit_test(
|
|
|
|
|
content,
|
|
|
|
|
size,
|
|
|
|
|
font,
|
|
|
|
|
bounds,
|
|
|
|
|
point,
|
|
|
|
|
nearest_only,
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-05-19 21:00:40 +02:00
|
|
|
}
|