summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-05 23:59:21 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-05 23:59:21 +0200
commit6d3e1d835e1688fbc58622a03a784ed25ed3f0e1 (patch)
treeb1a14b0ec7b2da4368d5c98850fe9e9eebc5490a /graphics
parent4a356cfc16f3b45d64826732009d9feeac016b28 (diff)
downloadiced-6d3e1d835e1688fbc58622a03a784ed25ed3f0e1.tar.gz
iced-6d3e1d835e1688fbc58622a03a784ed25ed3f0e1.tar.bz2
iced-6d3e1d835e1688fbc58622a03a784ed25ed3f0e1.zip
Decouple caching from layering and simplify everything
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/geometry/frame.rs16
-rw-r--r--graphics/src/mesh.rs16
-rw-r--r--graphics/src/text.rs4
3 files changed, 17 insertions, 19 deletions
diff --git a/graphics/src/geometry/frame.rs b/graphics/src/geometry/frame.rs
index ad35e8ec..377589d7 100644
--- a/graphics/src/geometry/frame.rs
+++ b/graphics/src/geometry/frame.rs
@@ -113,13 +113,11 @@ where
region: Rectangle,
f: impl FnOnce(&mut Self) -> R,
) -> R {
- let mut frame = self.draft(region.size());
+ let mut frame = self.draft(region);
let result = f(&mut frame);
- let origin = Point::new(region.x, region.y);
-
- self.paste(frame, origin);
+ self.paste(frame, Point::new(region.x, region.y));
result
}
@@ -129,14 +127,14 @@ where
/// Draw its contents back to this [`Frame`] with [`paste`].
///
/// [`paste`]: Self::paste
- pub fn draft(&mut self, size: Size) -> Self {
+ fn draft(&mut self, clip_bounds: Rectangle) -> Self {
Self {
- raw: self.raw.draft(size),
+ raw: self.raw.draft(clip_bounds),
}
}
/// Draws the contents of the given [`Frame`] with origin at the given [`Point`].
- pub fn paste(&mut self, frame: Self, at: Point) {
+ fn paste(&mut self, frame: Self, at: Point) {
self.raw.paste(frame.raw, at);
}
@@ -187,7 +185,7 @@ pub trait Backend: Sized {
fn scale(&mut self, scale: impl Into<f32>);
fn scale_nonuniform(&mut self, scale: impl Into<Vector>);
- fn draft(&mut self, size: Size) -> Self;
+ fn draft(&mut self, clip_bounds: Rectangle) -> Self;
fn paste(&mut self, frame: Self, at: Point);
fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>);
@@ -232,7 +230,7 @@ impl Backend for () {
fn scale(&mut self, _scale: impl Into<f32>) {}
fn scale_nonuniform(&mut self, _scale: impl Into<Vector>) {}
- fn draft(&mut self, _size: Size) -> Self {}
+ fn draft(&mut self, _clip_bounds: Rectangle) -> Self {}
fn paste(&mut self, _frame: Self, _at: Point) {}
fn stroke<'a>(&mut self, _path: &Path, _stroke: impl Into<Stroke<'a>>) {}
diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs
index d3e7ffaf..76602319 100644
--- a/graphics/src/mesh.rs
+++ b/graphics/src/mesh.rs
@@ -1,6 +1,6 @@
//! Draw triangles!
use crate::color;
-use crate::core::{Rectangle, Size, Transformation};
+use crate::core::{Rectangle, Transformation};
use crate::gradient;
use bytemuck::{Pod, Zeroable};
@@ -16,8 +16,8 @@ pub enum Mesh {
/// The [`Transformation`] for the vertices of the [`Mesh`].
transformation: Transformation,
- /// The [`Size`] of the [`Mesh`].
- size: Size,
+ /// The clip bounds of the [`Mesh`].
+ clip_bounds: Rectangle,
},
/// A mesh with a gradient.
Gradient {
@@ -27,8 +27,8 @@ pub enum Mesh {
/// The [`Transformation`] for the vertices of the [`Mesh`].
transformation: Transformation,
- /// The [`Size`] of the [`Mesh`].
- size: Size,
+ /// The clip bounds of the [`Mesh`].
+ clip_bounds: Rectangle,
},
}
@@ -53,15 +53,15 @@ impl Mesh {
pub fn clip_bounds(&self) -> Rectangle {
match self {
Self::Solid {
- size,
+ clip_bounds,
transformation,
..
}
| Self::Gradient {
- size,
+ clip_bounds,
transformation,
..
- } => Rectangle::with_size(*size) * *transformation,
+ } => *clip_bounds * *transformation,
}
}
}
diff --git a/graphics/src/text.rs b/graphics/src/text.rs
index c9c821c0..f9fc1fec 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -11,7 +11,7 @@ pub use cosmic_text;
use crate::core::alignment;
use crate::core::font::{self, Font};
-use crate::core::text::{LineHeight, Shaping};
+use crate::core::text::Shaping;
use crate::core::{Color, Pixels, Point, Rectangle, Size, Transformation};
use once_cell::sync::OnceCell;
@@ -50,7 +50,7 @@ pub enum Text {
/// The size of the text in logical pixels.
size: Pixels,
/// The line height of the text.
- line_height: LineHeight,
+ line_height: Pixels,
/// The font of the text.
font: Font,
/// The horizontal alignment of the text.