diff options
author | 2023-02-24 23:24:48 +0100 | |
---|---|---|
committer | 2023-02-24 23:24:48 +0100 | |
commit | 5100b5d0a1f654ec1254b7765ceadfb9091d6939 (patch) | |
tree | ac33dc79803af7040659380c0c94440b29e93e77 /renderer/src/backend.rs | |
parent | 368cadd25a8b57ee5c41e45d1abe8d1dfb194c69 (diff) | |
download | iced-5100b5d0a1f654ec1254b7765ceadfb9091d6939.tar.gz iced-5100b5d0a1f654ec1254b7765ceadfb9091d6939.tar.bz2 iced-5100b5d0a1f654ec1254b7765ceadfb9091d6939.zip |
Introduce `iced_renderer` subcrate featuring runtime renderer fallback
Diffstat (limited to 'renderer/src/backend.rs')
-rw-r--r-- | renderer/src/backend.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/renderer/src/backend.rs b/renderer/src/backend.rs new file mode 100644 index 00000000..a9a09593 --- /dev/null +++ b/renderer/src/backend.rs @@ -0,0 +1,94 @@ +use crate::{Font, Point, Size}; + +use iced_graphics::backend; +use iced_graphics::text; + +use std::borrow::Cow; + +pub enum Backend { + Wgpu(iced_wgpu::Backend), +} + +impl iced_graphics::Backend for Backend {} + +impl backend::Text for Backend { + const ICON_FONT: Font = Font::Name("Iced-Icons"); + const CHECKMARK_ICON: char = '\u{f00c}'; + const ARROW_DOWN_ICON: char = '\u{e800}'; + + fn default_font(&self) -> Font { + match self { + Self::Wgpu(backend) => backend.default_font(), + } + } + + fn default_size(&self) -> f32 { + match self { + Self::Wgpu(backend) => backend.default_size(), + } + } + + fn measure( + &self, + contents: &str, + size: f32, + font: Font, + bounds: Size, + ) -> (f32, f32) { + match self { + Self::Wgpu(backend) => { + backend.measure(contents, size, font, bounds) + } + } + } + + fn hit_test( + &self, + contents: &str, + size: f32, + font: Font, + bounds: Size, + position: Point, + nearest_only: bool, + ) -> Option<text::Hit> { + match self { + Self::Wgpu(backend) => backend.hit_test( + contents, + size, + font, + bounds, + position, + nearest_only, + ), + } + } + + fn load_font(&mut self, font: Cow<'static, [u8]>) { + match self { + Self::Wgpu(backend) => { + backend.load_font(font); + } + } + } +} + +#[cfg(feature = "image")] +impl backend::Image for Backend { + fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> { + match self { + Self::Wgpu(backend) => backend.dimensions(handle), + } + } +} + +#[cfg(feature = "svg")] +impl backend::Svg for Backend { + fn viewport_dimensions( + &self, + handle: &iced_native::svg::Handle, + ) -> Size<u32> { + match self { + Self::Wgpu(backend) => backend.viewport_dimensions(handle), + } + } +} |