summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-06 04:34:00 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-06 04:34:00 +0100
commitb205a663471a8170d7b30cc59894425c09bea563 (patch)
tree53514f16226949f1e2440eed8ead4dec968c8d95 /native
parent314b0f7dc52c844669c224060a7b03e842762370 (diff)
downloadiced-b205a663471a8170d7b30cc59894425c09bea563.tar.gz
iced-b205a663471a8170d7b30cc59894425c09bea563.tar.bz2
iced-b205a663471a8170d7b30cc59894425c09bea563.zip
Remove `appearance` from `Handle`
... and pass it directly to `Renderer::draw` instead.
Diffstat (limited to 'native')
-rw-r--r--native/src/svg.rs20
-rw-r--r--native/src/widget/helpers.rs2
-rw-r--r--native/src/widget/svg.rs15
3 files changed, 13 insertions, 24 deletions
diff --git a/native/src/svg.rs b/native/src/svg.rs
index 08b0984a..2168e409 100644
--- a/native/src/svg.rs
+++ b/native/src/svg.rs
@@ -1,19 +1,16 @@
//! Load and draw vector graphics.
-use crate::{Hasher, Rectangle, Size};
+use crate::{Color, Hasher, Rectangle, Size};
use std::borrow::Cow;
use std::hash::{Hash, Hasher as _};
use std::path::PathBuf;
use std::sync::Arc;
-pub use iced_style::svg::{Appearance, StyleSheet};
-
/// A handle of Svg data.
#[derive(Debug, Clone)]
pub struct Handle {
id: u64,
data: Arc<Data>,
- appearance: Appearance,
}
impl Handle {
@@ -39,7 +36,6 @@ impl Handle {
Handle {
id: hasher.finish(),
data: Arc::new(data),
- appearance: Appearance::default(),
}
}
@@ -52,16 +48,6 @@ impl Handle {
pub fn data(&self) -> &Data {
&self.data
}
-
- /// Returns the styling [`Appearance`] for the SVG.
- pub fn appearance(&self) -> Appearance {
- self.appearance
- }
-
- /// Set the [`Appearance`] for the SVG.
- pub fn set_appearance(&mut self, appearance: Appearance) {
- self.appearance = appearance;
- }
}
impl Hash for Handle {
@@ -98,6 +84,6 @@ pub trait Renderer: crate::Renderer {
/// Returns the default dimensions of an SVG for the given [`Handle`].
fn dimensions(&self, handle: &Handle) -> Size<u32>;
- /// Draws an SVG with the given [`Handle`] and inside the provided `bounds`.
- fn draw(&mut self, handle: Handle, bounds: Rectangle);
+ /// Draws an SVG with the given [`Handle`], an optional [`Color`] filter, and inside the provided `bounds`.
+ fn draw(&mut self, handle: Handle, color: Option<Color>, bounds: Rectangle);
}
diff --git a/native/src/widget/helpers.rs b/native/src/widget/helpers.rs
index e802f629..0bde288f 100644
--- a/native/src/widget/helpers.rs
+++ b/native/src/widget/helpers.rs
@@ -290,7 +290,7 @@ pub fn svg<Renderer>(
) -> widget::Svg<Renderer>
where
Renderer: crate::svg::Renderer,
- Renderer::Theme: crate::svg::StyleSheet,
+ Renderer::Theme: widget::svg::StyleSheet,
{
widget::Svg::new(handle)
}
diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs
index c7eb4f6d..f83f5acf 100644
--- a/native/src/widget/svg.rs
+++ b/native/src/widget/svg.rs
@@ -9,7 +9,8 @@ use crate::{
use std::path::PathBuf;
-pub use svg::{Handle, StyleSheet};
+pub use iced_style::svg::{Appearance, StyleSheet};
+pub use svg::Handle;
/// A vector graphics image.
///
@@ -17,7 +18,6 @@ pub use svg::{Handle, StyleSheet};
///
/// [`Svg`] images can have a considerable rendering cost when resized,
/// specially when they are complex.
-#[derive(Clone)]
#[allow(missing_debug_implementations)]
pub struct Svg<Renderer>
where
@@ -146,9 +146,6 @@ where
_cursor_position: Point,
_viewport: &Rectangle,
) {
- let mut handle = self.handle.clone();
- handle.set_appearance(theme.appearance(self.style));
-
let Size { width, height } = renderer.dimensions(&self.handle);
let image_size = Size::new(width as f32, height as f32);
@@ -167,7 +164,13 @@ where
..bounds
};
- renderer.draw(handle, drawing_bounds + offset);
+ let appearance = theme.appearance(&self.style);
+
+ renderer.draw(
+ self.handle.clone(),
+ appearance.color,
+ drawing_bounds + offset,
+ );
};
if adjusted_fit.width > bounds.width