diff options
author | 2023-11-29 22:28:31 +0100 | |
---|---|---|
committer | 2023-11-29 22:28:31 +0100 | |
commit | e09b4e24dda51b8212d8ece52431dacaa3922a7b (patch) | |
tree | 7005e181528134ebdde5bbbe5909273db9f30174 /renderer | |
parent | 83c7870c569a2976923ee6243a19813094d44673 (diff) | |
parent | 7f8b17604a31e00becc43130ec516c1a53552c88 (diff) | |
download | iced-e09b4e24dda51b8212d8ece52431dacaa3922a7b.tar.gz iced-e09b4e24dda51b8212d8ece52431dacaa3922a7b.tar.bz2 iced-e09b4e24dda51b8212d8ece52431dacaa3922a7b.zip |
Merge branch 'master' into feat/multi-window-support
Diffstat (limited to 'renderer')
-rw-r--r-- | renderer/Cargo.toml | 33 | ||||
-rw-r--r-- | renderer/src/compositor.rs | 12 | ||||
-rw-r--r-- | renderer/src/geometry.rs | 14 | ||||
-rw-r--r-- | renderer/src/geometry/cache.rs | 2 | ||||
-rw-r--r-- | renderer/src/lib.rs | 125 | ||||
-rw-r--r-- | renderer/src/settings.rs | 10 | ||||
-rw-r--r-- | renderer/src/widget.rs | 11 |
7 files changed, 117 insertions, 90 deletions
diff --git a/renderer/Cargo.toml b/renderer/Cargo.toml index fda2bc7b..56e17209 100644 --- a/renderer/Cargo.toml +++ b/renderer/Cargo.toml @@ -1,7 +1,14 @@ [package] name = "iced_renderer" -version = "0.1.0" -edition = "2021" +description = "The official renderer for iced" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true [features] wgpu = ["iced_wgpu"] @@ -10,21 +17,15 @@ svg = ["iced_tiny_skia/svg", "iced_wgpu?/svg"] geometry = ["iced_graphics/geometry", "iced_tiny_skia/geometry", "iced_wgpu?/geometry"] tracing = ["iced_wgpu?/tracing"] web-colors = ["iced_wgpu?/web-colors"] +webgl = ["iced_wgpu?/webgl"] [dependencies] -raw-window-handle = "0.5" -thiserror = "1" -log = "0.4" +iced_graphics.workspace = true +iced_tiny_skia.workspace = true -[dependencies.iced_graphics] -version = "0.8" -path = "../graphics" +iced_wgpu.workspace = true +iced_wgpu.optional = true -[dependencies.iced_tiny_skia] -version = "0.1" -path = "../tiny_skia" - -[dependencies.iced_wgpu] -version = "0.10" -path = "../wgpu" -optional = true +log.workspace = true +raw-window-handle.workspace = true +thiserror.workspace = true diff --git a/renderer/src/compositor.rs b/renderer/src/compositor.rs index b5da31bf..5fc5a459 100644 --- a/renderer/src/compositor.rs +++ b/renderer/src/compositor.rs @@ -249,7 +249,11 @@ impl Candidate { Ok(( Compositor::TinySkia(compositor), - Renderer::TinySkia(iced_tiny_skia::Renderer::new(backend)), + Renderer::TinySkia(iced_tiny_skia::Renderer::new( + backend, + settings.default_font, + settings.default_text_size, + )), )) } #[cfg(feature = "wgpu")] @@ -266,7 +270,11 @@ impl Candidate { Ok(( Compositor::Wgpu(compositor), - Renderer::Wgpu(iced_wgpu::Renderer::new(backend)), + Renderer::Wgpu(iced_wgpu::Renderer::new( + backend, + settings.default_font, + settings.default_text_size, + )), )) } #[cfg(not(feature = "wgpu"))] diff --git a/renderer/src/geometry.rs b/renderer/src/geometry.rs index 04b5d9e6..1ecb0a43 100644 --- a/renderer/src/geometry.rs +++ b/renderer/src/geometry.rs @@ -96,13 +96,11 @@ impl Frame { /// resulting glyphs will not be rotated or scaled properly. /// /// Additionally, all text will be rendered on top of all the layers of - /// a [`Canvas`]. Therefore, it is currently only meant to be used for + /// a `Canvas`. Therefore, it is currently only meant to be used for /// overlays, which is the most common use case. /// /// Support for vectorial text is planned, and should address all these /// limitations. - /// - /// [`Canvas`]: crate::widget::Canvas pub fn fill_text(&mut self, text: impl Into<Text>) { delegate!(self, frame, frame.fill_text(text)); } @@ -168,12 +166,18 @@ impl Frame { delegate!(self, frame, frame.rotate(angle)); } - /// Applies a scaling to the current transform of the [`Frame`]. + /// Applies a uniform scaling to the current transform of the [`Frame`]. #[inline] - pub fn scale(&mut self, scale: f32) { + pub fn scale(&mut self, scale: impl Into<f32>) { delegate!(self, frame, frame.scale(scale)); } + /// Applies a non-uniform scaling to the current transform of the [`Frame`]. + #[inline] + pub fn scale_nonuniform(&mut self, scale: impl Into<Vector>) { + delegate!(self, frame, frame.scale_nonuniform(scale)); + } + pub fn into_geometry(self) -> Geometry { match self { Self::TinySkia(frame) => Geometry::TinySkia(frame.into_primitive()), diff --git a/renderer/src/geometry/cache.rs b/renderer/src/geometry/cache.rs index d82e7f69..d4bb04b3 100644 --- a/renderer/src/geometry/cache.rs +++ b/renderer/src/geometry/cache.rs @@ -35,7 +35,7 @@ impl Cache { /// Creates a new empty [`Cache`]. pub fn new() -> Self { Cache { - state: Default::default(), + state: RefCell::default(), } } diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs index 7d1a02c2..1fc4c86b 100644 --- a/renderer/src/lib.rs +++ b/renderer/src/lib.rs @@ -1,3 +1,9 @@ +#![forbid(rust_2018_idioms)] +#![deny(unsafe_code, unused_results, rustdoc::broken_intra_doc_links)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#[cfg(feature = "wgpu")] +pub use iced_wgpu as wgpu; + pub mod compositor; #[cfg(feature = "geometry")] @@ -16,7 +22,9 @@ pub use geometry::Geometry; use crate::core::renderer; use crate::core::text::{self, Text}; -use crate::core::{Background, Font, Point, Rectangle, Size, Vector}; +use crate::core::{Background, Color, Font, Pixels, Point, Rectangle, Vector}; +use crate::graphics::text::Editor; +use crate::graphics::text::Paragraph; use crate::graphics::Mesh; use std::borrow::Cow; @@ -44,7 +52,7 @@ impl<T> Renderer<T> { pub fn draw_mesh(&mut self, mesh: Mesh) { match self { Self::TinySkia(_) => { - log::warn!("Unsupported mesh primitive: {:?}", mesh) + log::warn!("Unsupported mesh primitive: {mesh:?}"); } #[cfg(feature = "wgpu")] Self::Wgpu(renderer) => { @@ -142,6 +150,8 @@ impl<T> core::Renderer for Renderer<T> { impl<T> text::Renderer for Renderer<T> { type Font = Font; + type Paragraph = Paragraph; + type Editor = Editor; const ICON_FONT: Font = iced_tiny_skia::Renderer::<T>::ICON_FONT; const CHECKMARK_ICON: char = iced_tiny_skia::Renderer::<T>::CHECKMARK_ICON; @@ -152,59 +162,47 @@ impl<T> text::Renderer for Renderer<T> { delegate!(self, renderer, renderer.default_font()) } - fn default_size(&self) -> f32 { + fn default_size(&self) -> Pixels { delegate!(self, renderer, renderer.default_size()) } - fn measure( - &self, - content: &str, - size: f32, - line_height: text::LineHeight, - font: Font, - bounds: Size, - shaping: text::Shaping, - ) -> Size { + fn load_font(&mut self, bytes: Cow<'static, [u8]>) { + delegate!(self, renderer, renderer.load_font(bytes)); + } + + fn fill_paragraph( + &mut self, + paragraph: &Self::Paragraph, + position: Point, + color: Color, + ) { delegate!( self, renderer, - renderer.measure(content, size, line_height, font, bounds, shaping) - ) + renderer.fill_paragraph(paragraph, position, color) + ); } - fn hit_test( - &self, - content: &str, - size: f32, - line_height: text::LineHeight, - font: Font, - bounds: Size, - shaping: text::Shaping, - point: Point, - nearest_only: bool, - ) -> Option<text::Hit> { + fn fill_editor( + &mut self, + editor: &Self::Editor, + position: Point, + color: Color, + ) { delegate!( self, renderer, - renderer.hit_test( - content, - size, - line_height, - font, - bounds, - shaping, - point, - nearest_only - ) - ) - } - - fn load_font(&mut self, bytes: Cow<'static, [u8]>) { - delegate!(self, renderer, renderer.load_font(bytes)); + renderer.fill_editor(editor, position, color) + ); } - fn fill_text(&mut self, text: Text<'_, Self::Font>) { - delegate!(self, renderer, renderer.fill_text(text)); + fn fill_text( + &mut self, + text: Text<'_, Self::Font>, + position: Point, + color: Color, + ) { + delegate!(self, renderer, renderer.fill_text(text, position, color)); } } @@ -212,18 +210,26 @@ impl<T> text::Renderer for Renderer<T> { impl<T> crate::core::image::Renderer for Renderer<T> { type Handle = crate::core::image::Handle; - fn dimensions(&self, handle: &crate::core::image::Handle) -> Size<u32> { + fn dimensions( + &self, + handle: &crate::core::image::Handle, + ) -> core::Size<u32> { delegate!(self, renderer, renderer.dimensions(handle)) } - fn draw(&mut self, handle: crate::core::image::Handle, bounds: Rectangle) { - delegate!(self, renderer, renderer.draw(handle, bounds)); + fn draw( + &mut self, + handle: crate::core::image::Handle, + filter_method: crate::core::image::FilterMethod, + bounds: Rectangle, + ) { + delegate!(self, renderer, renderer.draw(handle, filter_method, bounds)); } } #[cfg(feature = "svg")] impl<T> crate::core::svg::Renderer for Renderer<T> { - fn dimensions(&self, handle: &crate::core::svg::Handle) -> Size<u32> { + fn dimensions(&self, handle: &crate::core::svg::Handle) -> core::Size<u32> { delegate!(self, renderer, renderer.dimensions(handle)) } @@ -233,7 +239,7 @@ impl<T> crate::core::svg::Renderer for Renderer<T> { color: Option<crate::core::Color>, bounds: Rectangle, ) { - delegate!(self, renderer, renderer.draw(handle, color, bounds)) + delegate!(self, renderer, renderer.draw(handle, color, bounds)); } } @@ -249,7 +255,8 @@ impl<T> crate::graphics::geometry::Renderer for Renderer<T> { crate::Geometry::TinySkia(primitive) => { renderer.draw_primitive(primitive); } - _ => unreachable!(), + #[cfg(feature = "wgpu")] + crate::Geometry::Wgpu(_) => unreachable!(), } } } @@ -260,10 +267,30 @@ impl<T> crate::graphics::geometry::Renderer for Renderer<T> { crate::Geometry::Wgpu(primitive) => { renderer.draw_primitive(primitive); } - _ => unreachable!(), + crate::Geometry::TinySkia(_) => unreachable!(), } } } } } } + +#[cfg(feature = "wgpu")] +impl<T> iced_wgpu::primitive::pipeline::Renderer for Renderer<T> { + fn draw_pipeline_primitive( + &mut self, + bounds: Rectangle, + primitive: impl wgpu::primitive::pipeline::Primitive, + ) { + match self { + Self::TinySkia(_renderer) => { + log::warn!( + "Custom shader primitive is unavailable with tiny-skia." + ); + } + Self::Wgpu(renderer) => { + renderer.draw_pipeline_primitive(bounds, primitive); + } + } + } +} diff --git a/renderer/src/settings.rs b/renderer/src/settings.rs index 2e51f339..432eb8a0 100644 --- a/renderer/src/settings.rs +++ b/renderer/src/settings.rs @@ -1,9 +1,7 @@ -use crate::core::Font; +use crate::core::{Font, Pixels}; use crate::graphics::Antialiasing; -/// The settings of a [`Backend`]. -/// -/// [`Backend`]: crate::Backend +/// The settings of a Backend. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Settings { /// The default [`Font`] to use. @@ -12,7 +10,7 @@ pub struct Settings { /// The default size of text. /// /// By default, it will be set to `16.0`. - pub default_text_size: f32, + pub default_text_size: Pixels, /// The antialiasing strategy that will be used for triangle primitives. /// @@ -24,7 +22,7 @@ impl Default for Settings { fn default() -> Settings { Settings { default_font: Font::default(), - default_text_size: 16.0, + default_text_size: Pixels(16.0), antialiasing: None, } } diff --git a/renderer/src/widget.rs b/renderer/src/widget.rs deleted file mode 100644 index 6c0c2a83..00000000 --- a/renderer/src/widget.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[cfg(feature = "canvas")] -pub mod canvas; - -#[cfg(feature = "canvas")] -pub use canvas::Canvas; - -#[cfg(feature = "qr_code")] -pub mod qr_code; - -#[cfg(feature = "qr_code")] -pub use qr_code::QRCode; |