summaryrefslogtreecommitdiffstats
path: root/widget/src/qr_code.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-03-12 18:17:19 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-12 18:17:19 +0100
commit3d915d3cb30e5d08829aa2928676a53c505a601e (patch)
tree4acb46e00ef3037aad6a8273ab67d4278d560784 /widget/src/qr_code.rs
parent34317bba5db0a0f9e3ffdbbac0d7136a32bd0f95 (diff)
parent98621aa344a7a0e1b23f320d21a4687af559998e (diff)
downloadiced-3d915d3cb30e5d08829aa2928676a53c505a601e.tar.gz
iced-3d915d3cb30e5d08829aa2928676a53c505a601e.tar.bz2
iced-3d915d3cb30e5d08829aa2928676a53c505a601e.zip
Merge pull request #2326 from iced-rs/closure-styles
Use closures for widget styling
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
}
}