diff options
author | 2020-05-29 02:00:28 +0200 | |
---|---|---|
committer | 2020-05-29 02:00:28 +0200 | |
commit | 0cde20b3550ede81bc7ddef628b91eec225aa8af (patch) | |
tree | 56920437979012cceb49718f2dd4ce27d5ba5d40 /graphics/src/backend.rs | |
parent | 67b6f044e870df41be92cdc79f571682b97a5d0d (diff) | |
parent | e11b5c614f5bf73c137b8b4f24f56047617527eb (diff) | |
download | iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.gz iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.bz2 iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.zip |
Merge branch 'master' into improvement/update-wgpu_glyph
Diffstat (limited to 'graphics/src/backend.rs')
-rw-r--r-- | graphics/src/backend.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs new file mode 100644 index 00000000..83510311 --- /dev/null +++ b/graphics/src/backend.rs @@ -0,0 +1,50 @@ +//! Write a graphics backend. +use iced_native::image; +use iced_native::svg; +use iced_native::{Font, Size}; + +/// The graphics backend of a [`Renderer`]. +/// +/// [`Renderer`]: ../struct.Renderer.html +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. + fn trim_measurements(&mut self) {} +} + +/// A graphics backend that supports text rendering. +pub trait Text { + /// The icon font of the backend. + const ICON_FONT: Font; + + /// The `char` representing a ✔ icon in the [`ICON_FONT`]. + /// + /// [`ICON_FONT`]: #associatedconst.ICON_FONt + 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. + fn measure( + &self, + contents: &str, + size: f32, + font: Font, + bounds: Size, + ) -> (f32, f32); +} + +/// A graphics backend that supports image rendering. +pub trait Image { + /// Returns the dimensions of the provided image. + fn dimensions(&self, handle: &image::Handle) -> (u32, u32); +} + +/// A graphics backend that supports SVG rendering. +pub trait Svg { + /// Returns the viewport dimensions of the provided SVG. + fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32); +} |