Introduce custom backend-specific primitives
This commit is contained in:
parent
8d65e40a11
commit
0ae1baa37b
28 changed files with 618 additions and 263 deletions
|
|
@ -7,4 +7,3 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["advanced"] }
|
iced = { path = "../..", features = ["advanced"] }
|
||||||
iced_graphics = { path = "../../graphics" }
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
//! This example showcases a simple native custom widget that renders using
|
//! This example showcases a simple native custom widget that renders using
|
||||||
//! arbitrary low-level geometry.
|
//! arbitrary low-level geometry.
|
||||||
mod rainbow {
|
mod rainbow {
|
||||||
use iced_graphics::primitive::{ColoredVertex2D, Primitive};
|
|
||||||
|
|
||||||
use iced::advanced::graphics::color;
|
use iced::advanced::graphics::color;
|
||||||
|
use iced::advanced::graphics::primitive::{ColoredVertex2D, Primitive};
|
||||||
use iced::advanced::layout::{self, Layout};
|
use iced::advanced::layout::{self, Layout};
|
||||||
use iced::advanced::renderer;
|
use iced::advanced::renderer;
|
||||||
use iced::advanced::widget::{self, Widget};
|
use iced::advanced::widget::{self, Widget};
|
||||||
|
|
@ -46,8 +45,8 @@ mod rainbow {
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
|
use iced::advanced::graphics::primitive::Mesh2D;
|
||||||
use iced::advanced::Renderer as _;
|
use iced::advanced::Renderer as _;
|
||||||
use iced_graphics::primitive::Mesh2D;
|
|
||||||
|
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
|
|
@ -135,7 +134,7 @@ mod rainbow {
|
||||||
renderer.with_translation(
|
renderer.with_translation(
|
||||||
Vector::new(bounds.x, bounds.y),
|
Vector::new(bounds.x, bounds.y),
|
||||||
|renderer| {
|
|renderer| {
|
||||||
renderer.draw_primitive(mesh);
|
renderer.draw_with_wgpu(mesh);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,9 @@ where
|
||||||
renderer.with_translation(
|
renderer.with_translation(
|
||||||
Vector::new(bounds.x, bounds.y),
|
Vector::new(bounds.x, bounds.y),
|
||||||
|renderer| {
|
|renderer| {
|
||||||
renderer.draw_primitive(geometry.0);
|
use iced::advanced::graphics::geometry::Renderer as _;
|
||||||
|
|
||||||
|
renderer.draw(vec![geometry]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,6 @@ features = ["derive"]
|
||||||
version = "0.9"
|
version = "0.9"
|
||||||
path = "../core"
|
path = "../core"
|
||||||
|
|
||||||
[dependencies.tiny-skia]
|
|
||||||
version = "0.9"
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dependencies.image]
|
[dependencies.image]
|
||||||
version = "0.24"
|
version = "0.24"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,13 @@ use iced_core::{Font, Point, Size};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
/// The graphics backend of a [`Renderer`].
|
||||||
|
///
|
||||||
|
/// [`Renderer`]: crate::Renderer
|
||||||
|
pub trait Backend {
|
||||||
|
type Primitive;
|
||||||
|
}
|
||||||
|
|
||||||
/// A graphics backend that supports text rendering.
|
/// A graphics backend that supports text rendering.
|
||||||
pub trait Text {
|
pub trait Text {
|
||||||
/// The icon font of the backend.
|
/// The icon font of the backend.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,68 @@
|
||||||
//! Track and compute the damage of graphical primitives.
|
//! Track and compute the damage of graphical primitives.
|
||||||
|
use crate::core::alignment;
|
||||||
use crate::core::{Rectangle, Size};
|
use crate::core::{Rectangle, Size};
|
||||||
use crate::Primitive;
|
use crate::Primitive;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Computes the damage regions between the two given primitives.
|
pub trait Damage: PartialEq {
|
||||||
pub fn regions(a: &Primitive, b: &Primitive) -> Vec<Rectangle> {
|
/// Returns the bounds of the [`Damage`].
|
||||||
|
fn bounds(&self) -> Rectangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Damage> Damage for Primitive<T> {
|
||||||
|
fn bounds(&self) -> Rectangle {
|
||||||
|
match self {
|
||||||
|
Self::Text {
|
||||||
|
bounds,
|
||||||
|
horizontal_alignment,
|
||||||
|
vertical_alignment,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let mut bounds = *bounds;
|
||||||
|
|
||||||
|
bounds.x = match horizontal_alignment {
|
||||||
|
alignment::Horizontal::Left => bounds.x,
|
||||||
|
alignment::Horizontal::Center => {
|
||||||
|
bounds.x - bounds.width / 2.0
|
||||||
|
}
|
||||||
|
alignment::Horizontal::Right => bounds.x - bounds.width,
|
||||||
|
};
|
||||||
|
|
||||||
|
bounds.y = match vertical_alignment {
|
||||||
|
alignment::Vertical::Top => bounds.y,
|
||||||
|
alignment::Vertical::Center => {
|
||||||
|
bounds.y - bounds.height / 2.0
|
||||||
|
}
|
||||||
|
alignment::Vertical::Bottom => bounds.y - bounds.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
bounds.expand(1.5)
|
||||||
|
}
|
||||||
|
Self::Quad { bounds, .. }
|
||||||
|
| Self::Image { bounds, .. }
|
||||||
|
| Self::Svg { bounds, .. } => bounds.expand(1.0),
|
||||||
|
Self::Clip { bounds, .. } => bounds.expand(1.0),
|
||||||
|
Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => {
|
||||||
|
Rectangle::with_size(*size)
|
||||||
|
}
|
||||||
|
Self::Group { primitives } => primitives
|
||||||
|
.iter()
|
||||||
|
.map(Self::bounds)
|
||||||
|
.fold(Rectangle::with_size(Size::ZERO), |a, b| {
|
||||||
|
Rectangle::union(&a, &b)
|
||||||
|
}),
|
||||||
|
Self::Translate {
|
||||||
|
translation,
|
||||||
|
content,
|
||||||
|
} => content.bounds() + *translation,
|
||||||
|
Self::Cache { content } => content.bounds(),
|
||||||
|
Self::Custom(custom) => custom.bounds(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn regions<T: Damage>(a: &Primitive<T>, b: &Primitive<T>) -> Vec<Rectangle> {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(
|
(
|
||||||
Primitive::Group {
|
Primitive::Group {
|
||||||
|
|
@ -76,7 +133,10 @@ pub fn regions(a: &Primitive, b: &Primitive) -> Vec<Rectangle> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the damage regions between the two given lists of primitives.
|
/// Computes the damage regions between the two given lists of primitives.
|
||||||
pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec<Rectangle> {
|
pub fn list<T: Damage>(
|
||||||
|
previous: &[Primitive<T>],
|
||||||
|
current: &[Primitive<T>],
|
||||||
|
) -> Vec<Rectangle> {
|
||||||
let damage = previous
|
let damage = previous
|
||||||
.iter()
|
.iter()
|
||||||
.zip(current)
|
.zip(current)
|
||||||
|
|
@ -93,7 +153,7 @@ pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec<Rectangle> {
|
||||||
|
|
||||||
// Extend damage by the added/removed primitives
|
// Extend damage by the added/removed primitives
|
||||||
damage
|
damage
|
||||||
.chain(bigger[smaller.len()..].iter().map(Primitive::bounds))
|
.chain(bigger[smaller.len()..].iter().map(Damage::bounds))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,10 @@ pub use text::Text;
|
||||||
|
|
||||||
pub use crate::gradient::{self, Gradient};
|
pub use crate::gradient::{self, Gradient};
|
||||||
|
|
||||||
use crate::Primitive;
|
|
||||||
|
|
||||||
/// A bunch of shapes that can be drawn.
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Geometry(pub Primitive);
|
|
||||||
|
|
||||||
impl From<Geometry> for Primitive {
|
|
||||||
fn from(geometry: Geometry) -> Self {
|
|
||||||
geometry.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A renderer capable of drawing some [`Geometry`].
|
/// A renderer capable of drawing some [`Geometry`].
|
||||||
pub trait Renderer: crate::core::Renderer {
|
pub trait Renderer: crate::core::Renderer {
|
||||||
|
type Geometry;
|
||||||
|
|
||||||
/// Draws the given layers of [`Geometry`].
|
/// Draws the given layers of [`Geometry`].
|
||||||
fn draw(&mut self, layers: Vec<Geometry>);
|
fn draw(&mut self, layers: Vec<Self::Geometry>);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||||
)]
|
)]
|
||||||
#![deny(
|
#![deny(
|
||||||
missing_debug_implementations,
|
//missing_debug_implementations,
|
||||||
missing_docs,
|
//missing_docs,
|
||||||
unsafe_code,
|
unsafe_code,
|
||||||
unused_results,
|
unused_results,
|
||||||
clippy::extra_unused_lifetimes,
|
clippy::extra_unused_lifetimes,
|
||||||
|
|
@ -41,7 +41,9 @@ pub mod geometry;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
|
|
||||||
pub use antialiasing::Antialiasing;
|
pub use antialiasing::Antialiasing;
|
||||||
|
pub use backend::Backend;
|
||||||
pub use compositor::Compositor;
|
pub use compositor::Compositor;
|
||||||
|
pub use damage::Damage;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use gradient::Gradient;
|
pub use gradient::Gradient;
|
||||||
pub use primitive::Primitive;
|
pub use primitive::Primitive;
|
||||||
|
|
@ -49,7 +51,4 @@ pub use renderer::Renderer;
|
||||||
pub use transformation::Transformation;
|
pub use transformation::Transformation;
|
||||||
pub use viewport::Viewport;
|
pub use viewport::Viewport;
|
||||||
|
|
||||||
#[cfg(feature = "geometry")]
|
|
||||||
pub use geometry::Geometry;
|
|
||||||
|
|
||||||
pub use iced_core as core;
|
pub use iced_core as core;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
/// A rendering primitive.
|
/// A rendering primitive.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[non_exhaustive]
|
pub enum Primitive<T> {
|
||||||
pub enum Primitive {
|
|
||||||
/// A text primitive
|
/// A text primitive
|
||||||
Text {
|
Text {
|
||||||
/// The contents of the text
|
/// The contents of the text
|
||||||
|
|
@ -90,41 +89,17 @@ pub enum Primitive {
|
||||||
/// Any geometry that falls out of this region will be clipped.
|
/// Any geometry that falls out of this region will be clipped.
|
||||||
size: Size,
|
size: Size,
|
||||||
},
|
},
|
||||||
/// A [`tiny_skia`] path filled with some paint.
|
|
||||||
#[cfg(feature = "tiny-skia")]
|
|
||||||
Fill {
|
|
||||||
/// The path to fill.
|
|
||||||
path: tiny_skia::Path,
|
|
||||||
/// The paint to use.
|
|
||||||
paint: tiny_skia::Paint<'static>,
|
|
||||||
/// The fill rule to follow.
|
|
||||||
rule: tiny_skia::FillRule,
|
|
||||||
/// The transform to apply to the path.
|
|
||||||
transform: tiny_skia::Transform,
|
|
||||||
},
|
|
||||||
/// A [`tiny_skia`] path stroked with some paint.
|
|
||||||
#[cfg(feature = "tiny-skia")]
|
|
||||||
Stroke {
|
|
||||||
/// The path to stroke.
|
|
||||||
path: tiny_skia::Path,
|
|
||||||
/// The paint to use.
|
|
||||||
paint: tiny_skia::Paint<'static>,
|
|
||||||
/// The stroke settings.
|
|
||||||
stroke: tiny_skia::Stroke,
|
|
||||||
/// The transform to apply to the path.
|
|
||||||
transform: tiny_skia::Transform,
|
|
||||||
},
|
|
||||||
/// A group of primitives
|
/// A group of primitives
|
||||||
Group {
|
Group {
|
||||||
/// The primitives of the group
|
/// The primitives of the group
|
||||||
primitives: Vec<Primitive>,
|
primitives: Vec<Primitive<T>>,
|
||||||
},
|
},
|
||||||
/// A clip primitive
|
/// A clip primitive
|
||||||
Clip {
|
Clip {
|
||||||
/// The bounds of the clip
|
/// The bounds of the clip
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
/// The content of the clip
|
/// The content of the clip
|
||||||
content: Box<Primitive>,
|
content: Box<Primitive<T>>,
|
||||||
},
|
},
|
||||||
/// A primitive that applies a translation
|
/// A primitive that applies a translation
|
||||||
Translate {
|
Translate {
|
||||||
|
|
@ -132,7 +107,7 @@ pub enum Primitive {
|
||||||
translation: Vector,
|
translation: Vector,
|
||||||
|
|
||||||
/// The primitive to translate
|
/// The primitive to translate
|
||||||
content: Box<Primitive>,
|
content: Box<Primitive<T>>,
|
||||||
},
|
},
|
||||||
/// A cached primitive.
|
/// A cached primitive.
|
||||||
///
|
///
|
||||||
|
|
@ -140,11 +115,13 @@ pub enum Primitive {
|
||||||
/// generation is expensive.
|
/// generation is expensive.
|
||||||
Cache {
|
Cache {
|
||||||
/// The cached primitive
|
/// The cached primitive
|
||||||
content: Arc<Primitive>,
|
content: Arc<Primitive<T>>,
|
||||||
},
|
},
|
||||||
|
/// A backend-specific primitive.
|
||||||
|
Custom(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Primitive {
|
impl<T> Primitive<T> {
|
||||||
/// Creates a [`Primitive::Group`].
|
/// Creates a [`Primitive::Group`].
|
||||||
pub fn group(primitives: Vec<Self>) -> Self {
|
pub fn group(primitives: Vec<Self>) -> Self {
|
||||||
Self::Group { primitives }
|
Self::Group { primitives }
|
||||||
|
|
@ -165,68 +142,6 @@ impl Primitive {
|
||||||
content: Box::new(self),
|
content: Box::new(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the bounds of the [`Primitive`].
|
|
||||||
pub fn bounds(&self) -> Rectangle {
|
|
||||||
match self {
|
|
||||||
Self::Text {
|
|
||||||
bounds,
|
|
||||||
horizontal_alignment,
|
|
||||||
vertical_alignment,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let mut bounds = *bounds;
|
|
||||||
|
|
||||||
bounds.x = match horizontal_alignment {
|
|
||||||
alignment::Horizontal::Left => bounds.x,
|
|
||||||
alignment::Horizontal::Center => {
|
|
||||||
bounds.x - bounds.width / 2.0
|
|
||||||
}
|
|
||||||
alignment::Horizontal::Right => bounds.x - bounds.width,
|
|
||||||
};
|
|
||||||
|
|
||||||
bounds.y = match vertical_alignment {
|
|
||||||
alignment::Vertical::Top => bounds.y,
|
|
||||||
alignment::Vertical::Center => {
|
|
||||||
bounds.y - bounds.height / 2.0
|
|
||||||
}
|
|
||||||
alignment::Vertical::Bottom => bounds.y - bounds.height,
|
|
||||||
};
|
|
||||||
|
|
||||||
bounds.expand(1.5)
|
|
||||||
}
|
|
||||||
Self::Quad { bounds, .. }
|
|
||||||
| Self::Image { bounds, .. }
|
|
||||||
| Self::Svg { bounds, .. } => bounds.expand(1.0),
|
|
||||||
Self::Clip { bounds, .. } => bounds.expand(1.0),
|
|
||||||
Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => {
|
|
||||||
Rectangle::with_size(*size)
|
|
||||||
}
|
|
||||||
#[cfg(feature = "tiny-skia")]
|
|
||||||
Self::Fill { path, .. } | Self::Stroke { path, .. } => {
|
|
||||||
let bounds = path.bounds();
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
x: bounds.x(),
|
|
||||||
y: bounds.y(),
|
|
||||||
width: bounds.width(),
|
|
||||||
height: bounds.height(),
|
|
||||||
}
|
|
||||||
.expand(1.0)
|
|
||||||
}
|
|
||||||
Self::Group { primitives } => primitives
|
|
||||||
.iter()
|
|
||||||
.map(Self::bounds)
|
|
||||||
.fold(Rectangle::with_size(Size::ZERO), |a, b| {
|
|
||||||
Rectangle::union(&a, &b)
|
|
||||||
}),
|
|
||||||
Self::Translate {
|
|
||||||
translation,
|
|
||||||
content,
|
|
||||||
} => content.bounds() + *translation,
|
|
||||||
Self::Cache { content } => content.bounds(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of [`Vertex2D`] and indices representing a list of triangles.
|
/// A set of [`Vertex2D`] and indices representing a list of triangles.
|
||||||
|
|
@ -268,9 +183,3 @@ unsafe impl Zeroable for GradientVertex2D {}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe impl Pod for GradientVertex2D {}
|
unsafe impl Pod for GradientVertex2D {}
|
||||||
|
|
||||||
impl From<()> for Primitive {
|
|
||||||
fn from(_: ()) -> Self {
|
|
||||||
Self::Group { primitives: vec![] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//! Create a renderer from a [`Backend`].
|
//! Create a renderer from a [`Backend`].
|
||||||
use crate::backend;
|
use crate::backend::{self, Backend};
|
||||||
use crate::Primitive;
|
use crate::Primitive;
|
||||||
|
|
||||||
use iced_core::image;
|
use iced_core::image;
|
||||||
|
|
@ -16,13 +16,13 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
/// A backend-agnostic renderer that supports all the built-in widgets.
|
/// A backend-agnostic renderer that supports all the built-in widgets.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Renderer<B, Theme> {
|
pub struct Renderer<B: Backend, Theme> {
|
||||||
backend: B,
|
backend: B,
|
||||||
primitives: Vec<Primitive>,
|
primitives: Vec<Primitive<B::Primitive>>,
|
||||||
theme: PhantomData<Theme>,
|
theme: PhantomData<Theme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B, T> Renderer<B, T> {
|
impl<B: Backend, T> Renderer<B, T> {
|
||||||
/// Creates a new [`Renderer`] from the given [`Backend`].
|
/// Creates a new [`Renderer`] from the given [`Backend`].
|
||||||
pub fn new(backend: B) -> Self {
|
pub fn new(backend: B) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -38,7 +38,7 @@ impl<B, T> Renderer<B, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enqueues the given [`Primitive`] in the [`Renderer`] for drawing.
|
/// Enqueues the given [`Primitive`] in the [`Renderer`] for drawing.
|
||||||
pub fn draw_primitive(&mut self, primitive: Primitive) {
|
pub fn draw_primitive(&mut self, primitive: Primitive<B::Primitive>) {
|
||||||
self.primitives.push(primitive);
|
self.primitives.push(primitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,13 +46,42 @@ impl<B, T> Renderer<B, T> {
|
||||||
/// of the [`Renderer`].
|
/// of the [`Renderer`].
|
||||||
pub fn with_primitives<O>(
|
pub fn with_primitives<O>(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(&mut B, &[Primitive]) -> O,
|
f: impl FnOnce(&mut B, &[Primitive<B::Primitive>]) -> O,
|
||||||
) -> O {
|
) -> O {
|
||||||
f(&mut self.backend, &self.primitives)
|
f(&mut self.backend, &self.primitives)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start_layer(&mut self) -> Vec<Primitive<B::Primitive>> {
|
||||||
|
std::mem::take(&mut self.primitives)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn end_layer(
|
||||||
|
&mut self,
|
||||||
|
primitives: Vec<Primitive<B::Primitive>>,
|
||||||
|
bounds: Rectangle,
|
||||||
|
) {
|
||||||
|
let layer = std::mem::replace(&mut self.primitives, primitives);
|
||||||
|
|
||||||
|
self.primitives.push(Primitive::group(layer).clip(bounds));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_translation(&mut self) -> Vec<Primitive<B::Primitive>> {
|
||||||
|
std::mem::take(&mut self.primitives)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn end_translation(
|
||||||
|
&mut self,
|
||||||
|
primitives: Vec<Primitive<B::Primitive>>,
|
||||||
|
translation: Vector,
|
||||||
|
) {
|
||||||
|
let layer = std::mem::replace(&mut self.primitives, primitives);
|
||||||
|
|
||||||
|
self.primitives
|
||||||
|
.push(Primitive::group(layer).translate(translation));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B, T> iced_core::Renderer for Renderer<B, T> {
|
impl<B: Backend, T> iced_core::Renderer for Renderer<B, T> {
|
||||||
type Theme = T;
|
type Theme = T;
|
||||||
|
|
||||||
fn layout<Message>(
|
fn layout<Message>(
|
||||||
|
|
@ -64,13 +93,11 @@ impl<B, T> iced_core::Renderer for Renderer<B, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
|
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
|
||||||
let current = std::mem::take(&mut self.primitives);
|
let current = self.start_layer();
|
||||||
|
|
||||||
f(self);
|
f(self);
|
||||||
|
|
||||||
let layer = std::mem::replace(&mut self.primitives, current);
|
self.end_layer(current, bounds);
|
||||||
|
|
||||||
self.primitives.push(Primitive::group(layer).clip(bounds));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_translation(
|
fn with_translation(
|
||||||
|
|
@ -78,14 +105,11 @@ impl<B, T> iced_core::Renderer for Renderer<B, T> {
|
||||||
translation: Vector,
|
translation: Vector,
|
||||||
f: impl FnOnce(&mut Self),
|
f: impl FnOnce(&mut Self),
|
||||||
) {
|
) {
|
||||||
let current = std::mem::take(&mut self.primitives);
|
let current = self.start_translation();
|
||||||
|
|
||||||
f(self);
|
f(self);
|
||||||
|
|
||||||
let layer = std::mem::replace(&mut self.primitives, current);
|
self.end_translation(current, translation);
|
||||||
|
|
||||||
self.primitives
|
|
||||||
.push(Primitive::group(layer).translate(translation));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_quad(
|
fn fill_quad(
|
||||||
|
|
@ -109,7 +133,7 @@ impl<B, T> iced_core::Renderer for Renderer<B, T> {
|
||||||
|
|
||||||
impl<B, T> text::Renderer for Renderer<B, T>
|
impl<B, T> text::Renderer for Renderer<B, T>
|
||||||
where
|
where
|
||||||
B: backend::Text,
|
B: Backend + backend::Text,
|
||||||
{
|
{
|
||||||
type Font = Font;
|
type Font = Font;
|
||||||
|
|
||||||
|
|
@ -188,7 +212,7 @@ where
|
||||||
|
|
||||||
impl<B, T> image::Renderer for Renderer<B, T>
|
impl<B, T> image::Renderer for Renderer<B, T>
|
||||||
where
|
where
|
||||||
B: backend::Image,
|
B: Backend + backend::Image,
|
||||||
{
|
{
|
||||||
type Handle = image::Handle;
|
type Handle = image::Handle;
|
||||||
|
|
||||||
|
|
@ -203,7 +227,7 @@ where
|
||||||
|
|
||||||
impl<B, T> svg::Renderer for Renderer<B, T>
|
impl<B, T> svg::Renderer for Renderer<B, T>
|
||||||
where
|
where
|
||||||
B: backend::Svg,
|
B: Backend + backend::Svg,
|
||||||
{
|
{
|
||||||
fn dimensions(&self, handle: &svg::Handle) -> Size<u32> {
|
fn dimensions(&self, handle: &svg::Handle) -> Size<u32> {
|
||||||
self.backend().viewport_dimensions(handle)
|
self.backend().viewport_dimensions(handle)
|
||||||
|
|
@ -222,11 +246,3 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "geometry")]
|
|
||||||
impl<B, T> crate::geometry::Renderer for Renderer<B, T> {
|
|
||||||
fn draw(&mut self, layers: Vec<crate::Geometry>) {
|
|
||||||
self.primitives
|
|
||||||
.extend(layers.into_iter().map(crate::Geometry::into));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -100,26 +100,28 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> Result<(), SurfaceError> {
|
) -> Result<(), SurfaceError> {
|
||||||
renderer.with_primitives(|backend, primitives| {
|
match (self, renderer, surface) {
|
||||||
match (self, backend, surface) {
|
|
||||||
(
|
(
|
||||||
Self::TinySkia(_compositor),
|
Self::TinySkia(_compositor),
|
||||||
crate::Backend::TinySkia(backend),
|
crate::Renderer::TinySkia(renderer),
|
||||||
Surface::TinySkia(surface),
|
Surface::TinySkia(surface),
|
||||||
) => iced_tiny_skia::window::compositor::present(
|
) => renderer.with_primitives(|backend, primitives| {
|
||||||
|
iced_tiny_skia::window::compositor::present(
|
||||||
backend,
|
backend,
|
||||||
surface,
|
surface,
|
||||||
primitives,
|
primitives,
|
||||||
viewport,
|
viewport,
|
||||||
background_color,
|
background_color,
|
||||||
overlay,
|
overlay,
|
||||||
),
|
)
|
||||||
|
}),
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
(
|
(
|
||||||
Self::Wgpu(compositor),
|
Self::Wgpu(compositor),
|
||||||
crate::Backend::Wgpu(backend),
|
crate::Renderer::Wgpu(renderer),
|
||||||
Surface::Wgpu(surface),
|
Surface::Wgpu(surface),
|
||||||
) => iced_wgpu::window::compositor::present(
|
) => renderer.with_primitives(|backend, primitives| {
|
||||||
|
iced_wgpu::window::compositor::present(
|
||||||
compositor,
|
compositor,
|
||||||
backend,
|
backend,
|
||||||
surface,
|
surface,
|
||||||
|
|
@ -127,14 +129,14 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
viewport,
|
viewport,
|
||||||
background_color,
|
background_color,
|
||||||
overlay,
|
overlay,
|
||||||
),
|
)
|
||||||
|
}),
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"The provided renderer or surface are not compatible \
|
"The provided renderer or surface are not compatible \
|
||||||
with the compositor."
|
with the compositor."
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn screenshot<T: AsRef<str>>(
|
fn screenshot<T: AsRef<str>>(
|
||||||
|
|
@ -145,12 +147,27 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
renderer.with_primitives(|backend, primitives| match (self, backend, surface) {
|
match (self, renderer, surface) {
|
||||||
(Self::TinySkia(_compositor), crate::Backend::TinySkia(backend), Surface::TinySkia(surface)) => {
|
(
|
||||||
iced_tiny_skia::window::compositor::screenshot(surface, backend, primitives, viewport, background_color, overlay)
|
Self::TinySkia(_compositor),
|
||||||
},
|
Renderer::TinySkia(renderer),
|
||||||
|
Surface::TinySkia(surface),
|
||||||
|
) => renderer.with_primitives(|backend, primitives| {
|
||||||
|
iced_tiny_skia::window::compositor::screenshot(
|
||||||
|
surface,
|
||||||
|
backend,
|
||||||
|
primitives,
|
||||||
|
viewport,
|
||||||
|
background_color,
|
||||||
|
overlay,
|
||||||
|
)
|
||||||
|
}),
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
(Self::Wgpu(compositor), crate::Backend::Wgpu(backend), Surface::Wgpu(_)) => {
|
(
|
||||||
|
Self::Wgpu(compositor),
|
||||||
|
Renderer::Wgpu(renderer),
|
||||||
|
Surface::Wgpu(_),
|
||||||
|
) => renderer.with_primitives(|backend, primitives| {
|
||||||
iced_wgpu::window::compositor::screenshot(
|
iced_wgpu::window::compositor::screenshot(
|
||||||
compositor,
|
compositor,
|
||||||
backend,
|
backend,
|
||||||
|
|
@ -159,12 +176,13 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
background_color,
|
background_color,
|
||||||
overlay,
|
overlay,
|
||||||
)
|
)
|
||||||
},
|
}),
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"The provided renderer or backend are not compatible with the compositor."
|
"The provided renderer or backend are not compatible \
|
||||||
|
with the compositor."
|
||||||
),
|
),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,7 +233,7 @@ impl Candidate {
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Compositor::TinySkia(compositor),
|
Compositor::TinySkia(compositor),
|
||||||
Renderer::new(crate::Backend::TinySkia(backend)),
|
Renderer::TinySkia(iced_tiny_skia::Renderer::new(backend)),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
|
|
@ -232,7 +250,7 @@ impl Candidate {
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Compositor::Wgpu(compositor),
|
Compositor::Wgpu(compositor),
|
||||||
Renderer::new(crate::Backend::Wgpu(backend)),
|
Renderer::Wgpu(iced_wgpu::Renderer::new(backend)),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "wgpu"))]
|
#[cfg(not(feature = "wgpu"))]
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ mod cache;
|
||||||
pub use cache::Cache;
|
pub use cache::Cache;
|
||||||
|
|
||||||
use crate::core::{Point, Rectangle, Size, Vector};
|
use crate::core::{Point, Rectangle, Size, Vector};
|
||||||
use crate::graphics::geometry::{Fill, Geometry, Path, Stroke, Text};
|
use crate::graphics::geometry::{Fill, Path, Stroke, Text};
|
||||||
use crate::Backend;
|
use crate::Renderer;
|
||||||
|
|
||||||
pub enum Frame {
|
pub enum Frame {
|
||||||
TinySkia(iced_tiny_skia::geometry::Frame),
|
TinySkia(iced_tiny_skia::geometry::Frame),
|
||||||
|
|
@ -12,6 +12,12 @@ pub enum Frame {
|
||||||
Wgpu(iced_wgpu::geometry::Frame),
|
Wgpu(iced_wgpu::geometry::Frame),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum Geometry {
|
||||||
|
TinySkia(iced_tiny_skia::Primitive),
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Wgpu(iced_wgpu::Primitive),
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! delegate {
|
macro_rules! delegate {
|
||||||
($frame:expr, $name:ident, $body:expr) => {
|
($frame:expr, $name:ident, $body:expr) => {
|
||||||
match $frame {
|
match $frame {
|
||||||
|
|
@ -23,13 +29,13 @@ macro_rules! delegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
pub fn new<Theme>(renderer: &crate::Renderer<Theme>, size: Size) -> Self {
|
pub fn new<Theme>(renderer: &Renderer<Theme>, size: Size) -> Self {
|
||||||
match renderer.backend() {
|
match renderer {
|
||||||
Backend::TinySkia(_) => {
|
Renderer::TinySkia(_) => {
|
||||||
Frame::TinySkia(iced_tiny_skia::geometry::Frame::new(size))
|
Frame::TinySkia(iced_tiny_skia::geometry::Frame::new(size))
|
||||||
}
|
}
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
Backend::Wgpu(_) => {
|
Renderer::Wgpu(_) => {
|
||||||
Frame::Wgpu(iced_wgpu::geometry::Frame::new(size))
|
Frame::Wgpu(iced_wgpu::geometry::Frame::new(size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,6 +175,10 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_geometry(self) -> Geometry {
|
pub fn into_geometry(self) -> Geometry {
|
||||||
Geometry(delegate!(self, frame, frame.into_primitive()))
|
match self {
|
||||||
|
Self::TinySkia(frame) => Geometry::TinySkia(frame.into_primitive()),
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(frame) => Geometry::Wgpu(frame.into_primitive()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::core::Size;
|
use crate::core::Size;
|
||||||
use crate::geometry::{Frame, Geometry};
|
use crate::geometry::{Frame, Geometry};
|
||||||
use crate::graphics::Primitive;
|
|
||||||
use crate::Renderer;
|
use crate::Renderer;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
@ -21,10 +20,17 @@ enum State {
|
||||||
Empty,
|
Empty,
|
||||||
Filled {
|
Filled {
|
||||||
bounds: Size,
|
bounds: Size,
|
||||||
primitive: Arc<Primitive>,
|
primitive: Internal,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum Internal {
|
||||||
|
TinySkia(Arc<iced_tiny_skia::Primitive>),
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Wgpu(Arc<iced_wgpu::Primitive>),
|
||||||
|
}
|
||||||
|
|
||||||
impl Cache {
|
impl Cache {
|
||||||
/// Creates a new empty [`Cache`].
|
/// Creates a new empty [`Cache`].
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
@ -62,11 +68,23 @@ impl Cache {
|
||||||
} = self.state.borrow().deref()
|
} = self.state.borrow().deref()
|
||||||
{
|
{
|
||||||
if *cached_bounds == bounds {
|
if *cached_bounds == bounds {
|
||||||
return Geometry(Primitive::Cache {
|
match primitive {
|
||||||
|
Internal::TinySkia(primitive) => {
|
||||||
|
return Geometry::TinySkia(
|
||||||
|
iced_tiny_skia::Primitive::Cache {
|
||||||
|
content: primitive.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Internal::Wgpu(primitive) => {
|
||||||
|
return Geometry::Wgpu(iced_wgpu::Primitive::Cache {
|
||||||
content: primitive.clone(),
|
content: primitive.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut frame = Frame::new(renderer, bounds);
|
let mut frame = Frame::new(renderer, bounds);
|
||||||
draw_fn(&mut frame);
|
draw_fn(&mut frame);
|
||||||
|
|
@ -74,7 +92,15 @@ impl Cache {
|
||||||
let primitive = {
|
let primitive = {
|
||||||
let geometry = frame.into_geometry();
|
let geometry = frame.into_geometry();
|
||||||
|
|
||||||
Arc::new(geometry.0)
|
match geometry {
|
||||||
|
Geometry::TinySkia(primitive) => {
|
||||||
|
Internal::TinySkia(Arc::new(primitive))
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Geometry::Wgpu(primitive) => {
|
||||||
|
Internal::Wgpu(Arc::new(primitive))
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
*self.state.borrow_mut() = State::Filled {
|
*self.state.borrow_mut() = State::Filled {
|
||||||
|
|
@ -82,6 +108,18 @@ impl Cache {
|
||||||
primitive: primitive.clone(),
|
primitive: primitive.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Geometry(Primitive::Cache { content: primitive })
|
match primitive {
|
||||||
|
Internal::TinySkia(primitive) => {
|
||||||
|
Geometry::TinySkia(iced_tiny_skia::Primitive::Cache {
|
||||||
|
content: primitive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Internal::Wgpu(primitive) => {
|
||||||
|
Geometry::Wgpu(iced_wgpu::Primitive::Cache {
|
||||||
|
content: primitive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,259 @@ pub mod compositor;
|
||||||
#[cfg(feature = "geometry")]
|
#[cfg(feature = "geometry")]
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
|
|
||||||
mod backend;
|
|
||||||
mod settings;
|
mod settings;
|
||||||
|
|
||||||
pub use iced_graphics as graphics;
|
pub use iced_graphics as graphics;
|
||||||
pub use iced_graphics::core;
|
pub use iced_graphics::core;
|
||||||
|
|
||||||
pub use backend::Backend;
|
|
||||||
pub use compositor::Compositor;
|
pub use compositor::Compositor;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
|
|
||||||
|
#[cfg(feature = "geometry")]
|
||||||
|
pub use geometry::Geometry;
|
||||||
|
|
||||||
|
use crate::core::renderer;
|
||||||
|
use crate::core::text::{self, Text};
|
||||||
|
use crate::core::{Background, Font, Point, Rectangle, Size, Vector};
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
/// The default graphics renderer for [`iced`].
|
/// The default graphics renderer for [`iced`].
|
||||||
///
|
///
|
||||||
/// [`iced`]: https://github.com/iced-rs/iced
|
/// [`iced`]: https://github.com/iced-rs/iced
|
||||||
pub type Renderer<Theme> = iced_graphics::Renderer<Backend, Theme>;
|
pub enum Renderer<Theme> {
|
||||||
|
TinySkia(iced_tiny_skia::Renderer<Theme>),
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Wgpu(iced_wgpu::Renderer<Theme>),
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! delegate {
|
||||||
|
($renderer:expr, $name:ident, $body:expr) => {
|
||||||
|
match $renderer {
|
||||||
|
Self::TinySkia($name) => $body,
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu($name) => $body,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Renderer<T> {
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
pub fn draw_with_wgpu(&mut self, primitive: iced_wgpu::Primitive) {
|
||||||
|
if let Self::Wgpu(renderer) = self {
|
||||||
|
renderer.draw_primitive(primitive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> core::Renderer for Renderer<T> {
|
||||||
|
type Theme = T;
|
||||||
|
|
||||||
|
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
|
||||||
|
match self {
|
||||||
|
Self::TinySkia(renderer) => {
|
||||||
|
let primitives = renderer.start_layer();
|
||||||
|
|
||||||
|
f(self);
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::TinySkia(renderer) => {
|
||||||
|
renderer.end_layer(primitives, bounds);
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(renderer) => {
|
||||||
|
let primitives = renderer.start_layer();
|
||||||
|
|
||||||
|
f(self);
|
||||||
|
|
||||||
|
match self {
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(renderer) => {
|
||||||
|
renderer.end_layer(primitives, bounds);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_translation(
|
||||||
|
&mut self,
|
||||||
|
translation: Vector,
|
||||||
|
f: impl FnOnce(&mut Self),
|
||||||
|
) {
|
||||||
|
match self {
|
||||||
|
Self::TinySkia(renderer) => {
|
||||||
|
let primitives = renderer.start_translation();
|
||||||
|
|
||||||
|
f(self);
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::TinySkia(renderer) => {
|
||||||
|
renderer.end_translation(primitives, translation);
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(renderer) => {
|
||||||
|
let primitives = renderer.start_translation();
|
||||||
|
|
||||||
|
f(self);
|
||||||
|
|
||||||
|
match self {
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(renderer) => {
|
||||||
|
renderer.end_translation(primitives, translation);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_quad(
|
||||||
|
&mut self,
|
||||||
|
quad: renderer::Quad,
|
||||||
|
background: impl Into<Background>,
|
||||||
|
) {
|
||||||
|
delegate!(self, renderer, renderer.fill_quad(quad, background));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear(&mut self) {
|
||||||
|
delegate!(self, renderer, renderer.clear());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> text::Renderer for Renderer<T> {
|
||||||
|
type Font = Font;
|
||||||
|
|
||||||
|
const ICON_FONT: Font = iced_tiny_skia::Renderer::<T>::ICON_FONT;
|
||||||
|
const CHECKMARK_ICON: char = iced_tiny_skia::Renderer::<T>::CHECKMARK_ICON;
|
||||||
|
const ARROW_DOWN_ICON: char =
|
||||||
|
iced_tiny_skia::Renderer::<T>::ARROW_DOWN_ICON;
|
||||||
|
|
||||||
|
fn default_font(&self) -> Self::Font {
|
||||||
|
delegate!(self, renderer, renderer.default_font())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_size(&self) -> f32 {
|
||||||
|
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 {
|
||||||
|
delegate!(
|
||||||
|
self,
|
||||||
|
renderer,
|
||||||
|
renderer.measure(content, size, line_height, font, bounds, shaping)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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> {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_text(&mut self, text: Text<'_, Self::Font>) {
|
||||||
|
delegate!(self, renderer, renderer.fill_text(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "image")]
|
||||||
|
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> {
|
||||||
|
delegate!(self, renderer, renderer.dimensions(handle))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, handle: crate::core::image::Handle, bounds: Rectangle) {
|
||||||
|
delegate!(self, renderer, renderer.draw(handle, bounds));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "svg")]
|
||||||
|
impl<T> crate::core::svg::Renderer for Renderer<T> {
|
||||||
|
fn dimensions(&self, handle: &crate::core::svg::Handle) -> Size<u32> {
|
||||||
|
delegate!(self, renderer, renderer.dimensions(handle))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(
|
||||||
|
&mut self,
|
||||||
|
handle: crate::core::svg::Handle,
|
||||||
|
color: Option<crate::core::Color>,
|
||||||
|
bounds: Rectangle,
|
||||||
|
) {
|
||||||
|
delegate!(self, renderer, renderer.draw(handle, color, bounds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "geometry")]
|
||||||
|
impl<T> crate::graphics::geometry::Renderer for Renderer<T> {
|
||||||
|
type Geometry = crate::Geometry;
|
||||||
|
|
||||||
|
fn draw(&mut self, layers: Vec<Self::Geometry>) {
|
||||||
|
match self {
|
||||||
|
Self::TinySkia(renderer) => {
|
||||||
|
for layer in layers {
|
||||||
|
match layer {
|
||||||
|
crate::Geometry::TinySkia(primitive) => {
|
||||||
|
renderer.draw_primitive(primitive);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Self::Wgpu(renderer) => {
|
||||||
|
for layer in layers {
|
||||||
|
match layer {
|
||||||
|
crate::Geometry::Wgpu(primitive) => {
|
||||||
|
renderer.draw_primitive(primitive);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ log = "0.4"
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.8"
|
version = "0.8"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
features = ["tiny-skia"]
|
|
||||||
|
|
||||||
[dependencies.cosmic-text]
|
[dependencies.cosmic-text]
|
||||||
git = "https://github.com/hecrj/cosmic-text.git"
|
git = "https://github.com/hecrj/cosmic-text.git"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ use crate::core::text;
|
||||||
use crate::core::Gradient;
|
use crate::core::Gradient;
|
||||||
use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
|
use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
|
||||||
use crate::graphics::backend;
|
use crate::graphics::backend;
|
||||||
use crate::graphics::{Primitive, Viewport};
|
use crate::graphics::{Damage, Viewport};
|
||||||
|
use crate::primitive::{self, Primitive};
|
||||||
use crate::Settings;
|
use crate::Settings;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -419,6 +420,13 @@ impl Backend {
|
||||||
self.raster_pipeline
|
self.raster_pipeline
|
||||||
.draw(handle, *bounds, pixels, transform, clip_mask);
|
.draw(handle, *bounds, pixels, transform, clip_mask);
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "image"))]
|
||||||
|
Primitive::Image { .. } => {
|
||||||
|
log::warn!(
|
||||||
|
"Unsupported primitive in `iced_tiny_skia`: {:?}",
|
||||||
|
primitive
|
||||||
|
);
|
||||||
|
}
|
||||||
#[cfg(feature = "svg")]
|
#[cfg(feature = "svg")]
|
||||||
Primitive::Svg {
|
Primitive::Svg {
|
||||||
handle,
|
handle,
|
||||||
|
|
@ -442,12 +450,19 @@ impl Backend {
|
||||||
clip_mask,
|
clip_mask,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Primitive::Fill {
|
#[cfg(not(feature = "svg"))]
|
||||||
|
Primitive::Svg { .. } => {
|
||||||
|
log::warn!(
|
||||||
|
"Unsupported primitive in `iced_tiny_skia`: {:?}",
|
||||||
|
primitive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Primitive::Custom(primitive::Custom::Fill {
|
||||||
path,
|
path,
|
||||||
paint,
|
paint,
|
||||||
rule,
|
rule,
|
||||||
transform,
|
transform,
|
||||||
} => {
|
}) => {
|
||||||
let bounds = path.bounds();
|
let bounds = path.bounds();
|
||||||
|
|
||||||
let physical_bounds = (Rectangle {
|
let physical_bounds = (Rectangle {
|
||||||
|
|
@ -475,12 +490,12 @@ impl Backend {
|
||||||
clip_mask,
|
clip_mask,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Primitive::Stroke {
|
Primitive::Custom(primitive::Custom::Stroke {
|
||||||
path,
|
path,
|
||||||
paint,
|
paint,
|
||||||
stroke,
|
stroke,
|
||||||
transform,
|
transform,
|
||||||
} => {
|
}) => {
|
||||||
let bounds = path.bounds();
|
let bounds = path.bounds();
|
||||||
|
|
||||||
let physical_bounds = (Rectangle {
|
let physical_bounds = (Rectangle {
|
||||||
|
|
@ -588,13 +603,6 @@ impl Backend {
|
||||||
primitive
|
primitive
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
// Not supported!
|
|
||||||
log::warn!(
|
|
||||||
"Unsupported primitive in `iced_tiny_skia`: {:?}",
|
|
||||||
primitive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -766,6 +774,10 @@ fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl iced_graphics::Backend for Backend {
|
||||||
|
type Primitive = primitive::Custom;
|
||||||
|
}
|
||||||
|
|
||||||
impl backend::Text for Backend {
|
impl backend::Text for Backend {
|
||||||
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
||||||
const CHECKMARK_ICON: char = '\u{f00c}';
|
const CHECKMARK_ICON: char = '\u{f00c}';
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::graphics::geometry::fill::{self, Fill};
|
||||||
use crate::graphics::geometry::stroke::{self, Stroke};
|
use crate::graphics::geometry::stroke::{self, Stroke};
|
||||||
use crate::graphics::geometry::{Path, Style, Text};
|
use crate::graphics::geometry::{Path, Style, Text};
|
||||||
use crate::graphics::Gradient;
|
use crate::graphics::Gradient;
|
||||||
use crate::graphics::Primitive;
|
use crate::primitive::{self, Primitive};
|
||||||
|
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
size: Size,
|
size: Size,
|
||||||
|
|
@ -42,12 +42,13 @@ impl Frame {
|
||||||
let Some(path) = convert_path(path) else { return };
|
let Some(path) = convert_path(path) else { return };
|
||||||
let fill = fill.into();
|
let fill = fill.into();
|
||||||
|
|
||||||
self.primitives.push(Primitive::Fill {
|
self.primitives
|
||||||
|
.push(Primitive::Custom(primitive::Custom::Fill {
|
||||||
path,
|
path,
|
||||||
paint: into_paint(fill.style),
|
paint: into_paint(fill.style),
|
||||||
rule: into_fill_rule(fill.rule),
|
rule: into_fill_rule(fill.rule),
|
||||||
transform: self.transform,
|
transform: self.transform,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill_rectangle(
|
pub fn fill_rectangle(
|
||||||
|
|
@ -59,7 +60,8 @@ impl Frame {
|
||||||
let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { return };
|
let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { return };
|
||||||
let fill = fill.into();
|
let fill = fill.into();
|
||||||
|
|
||||||
self.primitives.push(Primitive::Fill {
|
self.primitives
|
||||||
|
.push(Primitive::Custom(primitive::Custom::Fill {
|
||||||
path,
|
path,
|
||||||
paint: tiny_skia::Paint {
|
paint: tiny_skia::Paint {
|
||||||
anti_alias: false,
|
anti_alias: false,
|
||||||
|
|
@ -67,7 +69,7 @@ impl Frame {
|
||||||
},
|
},
|
||||||
rule: into_fill_rule(fill.rule),
|
rule: into_fill_rule(fill.rule),
|
||||||
transform: self.transform,
|
transform: self.transform,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
|
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
|
||||||
|
|
@ -76,12 +78,13 @@ impl Frame {
|
||||||
let stroke = stroke.into();
|
let stroke = stroke.into();
|
||||||
let skia_stroke = into_stroke(&stroke);
|
let skia_stroke = into_stroke(&stroke);
|
||||||
|
|
||||||
self.primitives.push(Primitive::Stroke {
|
self.primitives
|
||||||
|
.push(Primitive::Custom(primitive::Custom::Stroke {
|
||||||
path,
|
path,
|
||||||
paint: into_paint(stroke.style),
|
paint: into_paint(stroke.style),
|
||||||
stroke: skia_stroke,
|
stroke: skia_stroke,
|
||||||
transform: self.transform,
|
transform: self.transform,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill_text(&mut self, text: impl Into<Text>) {
|
pub fn fill_text(&mut self, text: impl Into<Text>) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
|
mod primitive;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod text;
|
mod text;
|
||||||
|
|
||||||
|
|
@ -17,6 +18,7 @@ pub use iced_graphics as graphics;
|
||||||
pub use iced_graphics::core;
|
pub use iced_graphics::core;
|
||||||
|
|
||||||
pub use backend::Backend;
|
pub use backend::Backend;
|
||||||
|
pub use primitive::Primitive;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
|
|
||||||
/// A [`tiny-skia`] graphics renderer for [`iced`].
|
/// A [`tiny-skia`] graphics renderer for [`iced`].
|
||||||
|
|
|
||||||
48
tiny_skia/src/primitive.rs
Normal file
48
tiny_skia/src/primitive.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
use crate::core::Rectangle;
|
||||||
|
use crate::graphics::Damage;
|
||||||
|
|
||||||
|
pub type Primitive = crate::graphics::Primitive<Custom>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum Custom {
|
||||||
|
/// A path filled with some paint.
|
||||||
|
Fill {
|
||||||
|
/// The path to fill.
|
||||||
|
path: tiny_skia::Path,
|
||||||
|
/// The paint to use.
|
||||||
|
paint: tiny_skia::Paint<'static>,
|
||||||
|
/// The fill rule to follow.
|
||||||
|
rule: tiny_skia::FillRule,
|
||||||
|
/// The transform to apply to the path.
|
||||||
|
transform: tiny_skia::Transform,
|
||||||
|
},
|
||||||
|
/// A path stroked with some paint.
|
||||||
|
Stroke {
|
||||||
|
/// The path to stroke.
|
||||||
|
path: tiny_skia::Path,
|
||||||
|
/// The paint to use.
|
||||||
|
paint: tiny_skia::Paint<'static>,
|
||||||
|
/// The stroke settings.
|
||||||
|
stroke: tiny_skia::Stroke,
|
||||||
|
/// The transform to apply to the path.
|
||||||
|
transform: tiny_skia::Transform,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Damage for Custom {
|
||||||
|
fn bounds(&self) -> Rectangle {
|
||||||
|
match self {
|
||||||
|
Self::Fill { path, .. } | Self::Stroke { path, .. } => {
|
||||||
|
let bounds = path.bounds();
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
x: bounds.x(),
|
||||||
|
y: bounds.y(),
|
||||||
|
width: bounds.width(),
|
||||||
|
height: bounds.height(),
|
||||||
|
}
|
||||||
|
.expand(1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::core::{Color, Rectangle, Size};
|
use crate::core::{Color, Rectangle, Size};
|
||||||
use crate::graphics::compositor::{self, Information};
|
use crate::graphics::compositor::{self, Information};
|
||||||
use crate::graphics::damage;
|
use crate::graphics::damage;
|
||||||
use crate::graphics::{Error, Primitive, Viewport};
|
use crate::graphics::{Error, Viewport};
|
||||||
use crate::{Backend, Renderer, Settings};
|
use crate::{Backend, Primitive, Renderer, Settings};
|
||||||
|
|
||||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ use crate::core;
|
||||||
use crate::core::{Color, Font, Point, Size};
|
use crate::core::{Color, Font, Point, Size};
|
||||||
use crate::graphics::backend;
|
use crate::graphics::backend;
|
||||||
use crate::graphics::color;
|
use crate::graphics::color;
|
||||||
use crate::graphics::{Primitive, Transformation, Viewport};
|
use crate::graphics::{Transformation, Viewport};
|
||||||
|
use crate::primitive::{self, Primitive};
|
||||||
use crate::quad;
|
use crate::quad;
|
||||||
use crate::text;
|
use crate::text;
|
||||||
use crate::triangle;
|
use crate::triangle;
|
||||||
|
|
@ -334,6 +335,10 @@ impl Backend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl crate::graphics::Backend for Backend {
|
||||||
|
type Primitive = primitive::Custom;
|
||||||
|
}
|
||||||
|
|
||||||
impl backend::Text for Backend {
|
impl backend::Text for Backend {
|
||||||
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
||||||
const CHECKMARK_ICON: char = '\u{f00c}';
|
const CHECKMARK_ICON: char = '\u{f00c}';
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ use crate::graphics::geometry::fill::{self, Fill};
|
||||||
use crate::graphics::geometry::{
|
use crate::graphics::geometry::{
|
||||||
LineCap, LineDash, LineJoin, Path, Stroke, Style, Text,
|
LineCap, LineDash, LineJoin, Path, Stroke, Style, Text,
|
||||||
};
|
};
|
||||||
use crate::graphics::primitive::{self, Primitive};
|
use crate::graphics::gradient::{self, Gradient};
|
||||||
use crate::graphics::Gradient;
|
use crate::graphics::primitive;
|
||||||
|
use crate::Primitive;
|
||||||
|
|
||||||
use iced_graphics::gradient;
|
|
||||||
use lyon::geom::euclid;
|
use lyon::geom::euclid;
|
||||||
use lyon::tessellation;
|
use lyon::tessellation;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ use crate::core;
|
||||||
use crate::core::alignment;
|
use crate::core::alignment;
|
||||||
use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
|
use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
|
||||||
use crate::graphics::color;
|
use crate::graphics::color;
|
||||||
use crate::graphics::{Primitive, Viewport};
|
use crate::graphics::Viewport;
|
||||||
use crate::quad::{self, Quad};
|
use crate::quad::{self, Quad};
|
||||||
|
use crate::Primitive;
|
||||||
|
|
||||||
/// A group of primitives that should be clipped together.
|
/// A group of primitives that should be clipped together.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -262,13 +263,7 @@ impl<'a> Layer<'a> {
|
||||||
current_layer,
|
current_layer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
Primitive::Custom(()) => {}
|
||||||
// Not supported!
|
|
||||||
log::warn!(
|
|
||||||
"Unsupported primitive in `iced_wgpu`: {:?}",
|
|
||||||
primitive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||||
)]
|
)]
|
||||||
#![deny(
|
#![deny(
|
||||||
missing_debug_implementations,
|
//missing_debug_implementations,
|
||||||
missing_docs,
|
//missing_docs,
|
||||||
unsafe_code,
|
unsafe_code,
|
||||||
unused_results,
|
unused_results,
|
||||||
clippy::extra_unused_lifetimes,
|
clippy::extra_unused_lifetimes,
|
||||||
|
|
@ -47,6 +47,7 @@ pub mod geometry;
|
||||||
mod backend;
|
mod backend;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
mod color;
|
mod color;
|
||||||
|
mod primitive;
|
||||||
mod quad;
|
mod quad;
|
||||||
mod text;
|
mod text;
|
||||||
mod triangle;
|
mod triangle;
|
||||||
|
|
@ -60,6 +61,7 @@ pub use wgpu;
|
||||||
|
|
||||||
pub use backend::Backend;
|
pub use backend::Backend;
|
||||||
pub use layer::Layer;
|
pub use layer::Layer;
|
||||||
|
pub use primitive::Primitive;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
|
|
||||||
#[cfg(any(feature = "image", feature = "svg"))]
|
#[cfg(any(feature = "image", feature = "svg"))]
|
||||||
|
|
|
||||||
3
wgpu/src/primitive.rs
Normal file
3
wgpu/src/primitive.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub type Primitive = crate::graphics::Primitive<Custom>;
|
||||||
|
|
||||||
|
pub type Custom = ();
|
||||||
|
|
@ -3,8 +3,8 @@ use crate::core::{Color, Size};
|
||||||
use crate::graphics;
|
use crate::graphics;
|
||||||
use crate::graphics::color;
|
use crate::graphics::color;
|
||||||
use crate::graphics::compositor;
|
use crate::graphics::compositor;
|
||||||
use crate::graphics::{Error, Primitive, Viewport};
|
use crate::graphics::{Error, Viewport};
|
||||||
use crate::{Backend, Renderer, Settings};
|
use crate::{Backend, Primitive, Renderer, Settings};
|
||||||
|
|
||||||
use futures::stream::{self, StreamExt};
|
use futures::stream::{self, StreamExt};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::canvas::event::{self, Event};
|
use crate::canvas::event::{self, Event};
|
||||||
use crate::canvas::mouse;
|
use crate::canvas::mouse;
|
||||||
use crate::core::Rectangle;
|
use crate::core::Rectangle;
|
||||||
use crate::graphics::geometry::{self, Geometry};
|
use crate::graphics::geometry;
|
||||||
|
|
||||||
/// The state and logic of a [`Canvas`].
|
/// The state and logic of a [`Canvas`].
|
||||||
///
|
///
|
||||||
|
|
@ -51,7 +51,7 @@ where
|
||||||
theme: &Renderer::Theme,
|
theme: &Renderer::Theme,
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
) -> Vec<Geometry>;
|
) -> Vec<Renderer::Geometry>;
|
||||||
|
|
||||||
/// Returns the current mouse interaction of the [`Program`].
|
/// Returns the current mouse interaction of the [`Program`].
|
||||||
///
|
///
|
||||||
|
|
@ -93,7 +93,7 @@ where
|
||||||
theme: &Renderer::Theme,
|
theme: &Renderer::Theme,
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
) -> Vec<Geometry> {
|
) -> Vec<Renderer::Geometry> {
|
||||||
T::draw(self, state, renderer, theme, bounds, cursor)
|
T::draw(self, state, renderer, theme, bounds, cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::core::widget::Tree;
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
use crate::graphics::geometry::Renderer as _;
|
||||||
use crate::Renderer;
|
use crate::Renderer;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -121,7 +122,7 @@ impl<'a, Message, Theme> Widget<Message, Renderer<Theme>> for QRCode<'a> {
|
||||||
let translation = Vector::new(bounds.x, bounds.y);
|
let translation = Vector::new(bounds.x, bounds.y);
|
||||||
|
|
||||||
renderer.with_translation(translation, |renderer| {
|
renderer.with_translation(translation, |renderer| {
|
||||||
renderer.draw_primitive(geometry.0);
|
renderer.draw(vec![geometry]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue