summaryrefslogtreecommitdiffstats
path: root/widget/src/qr_code.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-12 14:51:30 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-12 14:52:29 +0100
commit67416302180ce27c81418b71798d02b52c44e625 (patch)
treef03d08859b57eee51f58729ab022540f17321a9e /widget/src/qr_code.rs
parentafd138dba697976f61e335555b69417c4c84f7f2 (diff)
downloadiced-67416302180ce27c81418b71798d02b52c44e625.tar.gz
iced-67416302180ce27c81418b71798d02b52c44e625.tar.bz2
iced-67416302180ce27c81418b71798d02b52c44e625.zip
Use closures for `QRCode::style`
Diffstat (limited to '')
-rw-r--r--widget/src/qr_code.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs
index 41bcb83e..90c0c970 100644
--- a/widget/src/qr_code.rs
+++ b/widget/src/qr_code.rs
@@ -19,23 +19,23 @@ const QUIET_ZONE: usize = 2;
/// A type of matrix barcode consisting of squares arranged in a grid which
/// can be read by an imaging device, such as a camera.
-#[derive(Debug)]
+#[allow(missing_debug_implementations)]
pub struct QRCode<'a, Theme = crate::Theme> {
data: &'a Data,
cell_size: u16,
- style: Style<Theme>,
+ style: Style<'a, Theme>,
}
impl<'a, Theme> QRCode<'a, Theme> {
/// Creates a new [`QRCode`] with the provided [`Data`].
pub fn new(data: &'a Data) -> Self
where
- Theme: DefaultStyle,
+ Theme: DefaultStyle + 'a,
{
Self {
data,
cell_size: DEFAULT_CELL_SIZE,
- style: Theme::default_style(),
+ style: Box::new(Theme::default_style),
}
}
@@ -46,8 +46,8 @@ impl<'a, Theme> QRCode<'a, Theme> {
}
/// Sets the style of the [`QRCode`].
- pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
- self.style = style.into();
+ pub fn style(mut self, style: impl Fn(&Theme) -> Appearance + 'a) -> Self {
+ self.style = Box::new(style);
self
}
}
@@ -336,23 +336,23 @@ pub struct Appearance {
}
/// The style of a [`QRCode`].
-pub type Style<Theme> = fn(&Theme) -> Appearance;
+pub type Style<'a, Theme> = Box<dyn Fn(&Theme) -> Appearance + 'a>;
/// The default style of a [`QRCode`].
pub trait DefaultStyle {
/// Returns the default style of a [`QRCode`].
- fn default_style() -> Style<Self>;
+ fn default_style(&self) -> Appearance;
}
impl DefaultStyle for Theme {
- fn default_style() -> Style<Self> {
- default
+ fn default_style(&self) -> Appearance {
+ default(self)
}
}
impl DefaultStyle for Appearance {
- fn default_style() -> Style<Self> {
- |appearance| *appearance
+ fn default_style(&self) -> Appearance {
+ *self
}
}