summaryrefslogtreecommitdiffstats
path: root/core/src/background/background_image.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-20 11:57:26 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-20 11:57:26 +0000
commit27b099c895825ee03555fd7bdaa8cefdb2125ead (patch)
tree4b77fc19db7785884c4a67e85e452bb140e13688 /core/src/background/background_image.rs
parentbae25b74f68078e5ff74cdae717273cf315d4e90 (diff)
downloadiced-master.tar.gz
iced-master.tar.bz2
iced-master.zip
WIP: background image supportmaster
Diffstat (limited to 'core/src/background/background_image.rs')
-rw-r--r--core/src/background/background_image.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/core/src/background/background_image.rs b/core/src/background/background_image.rs
new file mode 100644
index 00000000..75d63dfc
--- /dev/null
+++ b/core/src/background/background_image.rs
@@ -0,0 +1,60 @@
+use crate::{Image, Point, Size};
+
+/// A background image.
+#[derive(Debug, Clone, PartialEq)]
+pub struct BackgroundImage {
+ // TODO: svg support
+ image: Image,
+ attachment: Attachment,
+ clip: Sizing,
+ origin: Sizing,
+ /// (x, y)
+ repeat: (Repeat, Repeat),
+ size: Size,
+ // filter_method: FilterMethod,
+ // opacity: f32,
+ // TODO: blend mode
+}
+
+impl BackgroundImage {
+ /// Scales the opacity of the [`BackgroundImage`] by the given factor.
+ pub fn scale_opacity(mut self, factor: f32) -> Self {
+ let opacity = self.image.opacity * factor;
+ self.image = self.image.opacity(opacity);
+ self
+ }
+}
+
+/// An attachment property.
+#[derive(Debug, Clone, Copy, PartialEq, Default)]
+pub enum Attachment {
+ /// Fixed relative to the viewport.
+ Fixed,
+ /// Fixed relative to self.
+ #[default]
+ Local,
+}
+
+/// A sizing property.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum Sizing {
+ /// At outside edge of border.
+ Border,
+ /// At outside edge of padding.
+ Padding,
+ /// At outside edge of content.
+ Content,
+}
+
+/// A repetition property.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum Repeat {
+ /// Repeat beginning at offset. Will be clipped if necessary.
+ Repeat(Point),
+ /// Repeated as much as possible without clipping. Whitespace is evenly distributed between each instance.
+ Space,
+ /// Repeated as much as possible without clipping. Stretched until there is room for another to be added.
+ Round,
+ /// No repetition. Position defined by point. Will be clipped if necessary.
+ NoRepeat(Point),
+}