summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor <hector@hecrj.dev>2024-10-02 17:23:33 +0200
committerLibravatar GitHub <noreply@github.com>2024-10-02 17:23:33 +0200
commit4a080e27ab05d33b6c053328a21746ac0af0e2a0 (patch)
treefe9fc2086dccec841bfd08da4f5493332b903ffe /widget
parentd5f278b31de1ba2d3df6cc8e1e617649e1f21869 (diff)
parentb02ec8b6b2f2bea68256a91e2a8a8c17198d4ce2 (diff)
downloadiced-4a080e27ab05d33b6c053328a21746ac0af0e2a0.tar.gz
iced-4a080e27ab05d33b6c053328a21746ac0af0e2a0.tar.bz2
iced-4a080e27ab05d33b6c053328a21746ac0af0e2a0.zip
Merge pull request #2606 from tvolk131/qr_code_fixed_size
feat: set total size of QRCode
Diffstat (limited to 'widget')
-rw-r--r--widget/src/qr_code.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs
index 21dee6b1..d1834465 100644
--- a/widget/src/qr_code.rs
+++ b/widget/src/qr_code.rs
@@ -26,15 +26,15 @@ use crate::core::mouse;
use crate::core::renderer::{self, Renderer as _};
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- Color, Element, Layout, Length, Point, Rectangle, Size, Theme, Vector,
- Widget,
+ Color, Element, Layout, Length, Pixels, Point, Rectangle, Size, Theme,
+ Vector, Widget,
};
use crate::Renderer;
use std::cell::RefCell;
use thiserror::Error;
-const DEFAULT_CELL_SIZE: u16 = 4;
+const DEFAULT_CELL_SIZE: f32 = 4.0;
const QUIET_ZONE: usize = 2;
/// A type of matrix barcode consisting of squares arranged in a grid which
@@ -66,7 +66,7 @@ where
Theme: Catalog,
{
data: &'a Data,
- cell_size: u16,
+ cell_size: f32,
class: Theme::Class<'a>,
}
@@ -84,8 +84,16 @@ where
}
/// Sets the size of the squares of the grid cell of the [`QRCode`].
- pub fn cell_size(mut self, cell_size: u16) -> Self {
- self.cell_size = cell_size;
+ pub fn cell_size(mut self, cell_size: impl Into<Pixels>) -> Self {
+ self.cell_size = cell_size.into().0;
+ self
+ }
+
+ /// Sets the size of the entire [`QRCode`].
+ pub fn total_size(mut self, total_size: impl Into<Pixels>) -> Self {
+ self.cell_size =
+ total_size.into().0 / (self.data.width + 2 * QUIET_ZONE) as f32;
+
self
}
@@ -133,8 +141,8 @@ where
_renderer: &Renderer,
_limits: &layout::Limits,
) -> layout::Node {
- let side_length = (self.data.width + 2 * QUIET_ZONE) as f32
- * f32::from(self.cell_size);
+ let side_length =
+ (self.data.width + 2 * QUIET_ZONE) as f32 * self.cell_size;
layout::Node::new(Size::new(side_length, side_length))
}