Draft (very) basic incremental rendering for iced_tiny_skia
This commit is contained in:
parent
6fae8bf6cb
commit
0f7abffc0e
10 changed files with 286 additions and 92 deletions
|
|
@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||
use std::sync::Arc;
|
||||
|
||||
/// A handle of some image data.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Handle {
|
||||
id: u64,
|
||||
data: Data,
|
||||
|
|
@ -156,6 +156,34 @@ impl std::fmt::Debug for Data {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Data {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::Path(a), Self::Path(b)) => a == b,
|
||||
(Self::Bytes(a), Self::Bytes(b)) => a.as_ref() == b.as_ref(),
|
||||
(
|
||||
Self::Rgba {
|
||||
width: width_a,
|
||||
height: height_a,
|
||||
pixels: pixels_a,
|
||||
},
|
||||
Self::Rgba {
|
||||
width: width_b,
|
||||
height: height_b,
|
||||
pixels: pixels_b,
|
||||
},
|
||||
) => {
|
||||
width_a == width_b
|
||||
&& height_a == height_b
|
||||
&& pixels_a.as_ref() == pixels_b.as_ref()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Data {}
|
||||
|
||||
/// A [`Renderer`] that can render raster graphics.
|
||||
///
|
||||
/// [renderer]: crate::renderer
|
||||
|
|
|
|||
|
|
@ -100,6 +100,30 @@ impl Rectangle<f32> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns whether the [`Rectangle`] intersects with the given one.
|
||||
pub fn intersects(&self, other: &Self) -> bool {
|
||||
self.intersection(other).is_some()
|
||||
}
|
||||
|
||||
/// Computes the union with the given [`Rectangle`].
|
||||
pub fn union(&self, other: &Self) -> Self {
|
||||
let x = self.x.min(other.x);
|
||||
let y = self.y.min(other.y);
|
||||
|
||||
let lower_right_x = (self.x + self.width).max(other.x + other.width);
|
||||
let lower_right_y = (self.y + self.height).max(other.y + other.height);
|
||||
|
||||
let width = lower_right_x - x;
|
||||
let height = lower_right_y - y;
|
||||
|
||||
Rectangle {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
/// Snaps the [`Rectangle`] to __unsigned__ integer coordinates.
|
||||
pub fn snap(self) -> Rectangle<u32> {
|
||||
Rectangle {
|
||||
|
|
@ -109,6 +133,16 @@ impl Rectangle<f32> {
|
|||
height: self.height as u32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Expands the [`Rectangle`] a given amount.
|
||||
pub fn expand(self, amount: f32) -> Self {
|
||||
Self {
|
||||
x: self.x - amount,
|
||||
y: self.y - amount,
|
||||
width: self.width + amount * 2.0,
|
||||
height: self.height + amount * 2.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for Rectangle<f32> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::path::PathBuf;
|
|||
use std::sync::Arc;
|
||||
|
||||
/// A handle of Svg data.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Handle {
|
||||
id: u64,
|
||||
data: Arc<Data>,
|
||||
|
|
@ -57,7 +57,7 @@ impl Hash for Handle {
|
|||
}
|
||||
|
||||
/// The data of a vectorial image.
|
||||
#[derive(Clone, Hash)]
|
||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||
pub enum Data {
|
||||
/// File data
|
||||
Path(PathBuf),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue