iced-yoda/graphics/src/backend.rs

51 lines
1.5 KiB
Rust
Raw Normal View History

//! Write a graphics backend.
2020-05-19 17:15:44 +02:00
use iced_native::image;
use iced_native::svg;
use iced_native::{Font, Size};
/// The graphics backend of a [`Renderer`].
///
/// [`Renderer`]: ../struct.Renderer.html
2020-05-19 17:15:44 +02:00
pub trait Backend {
/// Trims the measurements cache.
///
/// This method is currently necessary to properly trim the text cache in
/// `iced_wgpu` and `iced_glow` because of limitations in the text rendering
/// pipeline. It will be removed in the future.
2020-05-19 17:15:44 +02:00
fn trim_measurements(&mut self) {}
}
/// A graphics backend that supports text rendering.
2020-05-19 17:15:44 +02:00
pub trait Text {
/// The icon font of the backend.
2020-05-19 17:15:44 +02:00
const ICON_FONT: Font;
/// The `char` representing a ✔ icon in the [`ICON_FONT`].
///
/// [`ICON_FONT`]: #associatedconst.ICON_FONt
2020-05-19 17:15:44 +02:00
const CHECKMARK_ICON: char;
/// Measures the text contents with the given size and font,
/// returning the size of a laid out paragraph that fits in the provided
/// bounds.
2020-05-19 17:15:44 +02:00
fn measure(
&self,
contents: &str,
size: f32,
font: Font,
bounds: Size,
) -> (f32, f32);
}
/// A graphics backend that supports image rendering.
2020-05-19 17:15:44 +02:00
pub trait Image {
/// Returns the dimensions of the provided image.
2020-05-19 17:15:44 +02:00
fn dimensions(&self, handle: &image::Handle) -> (u32, u32);
}
/// A graphics backend that supports SVG rendering.
2020-05-19 17:15:44 +02:00
pub trait Svg {
/// Returns the viewport dimensions of the provided SVG.
2020-05-19 17:15:44 +02:00
fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32);
}