diff options
author | 2024-09-24 20:57:53 -0500 | |
---|---|---|
committer | 2024-09-24 20:57:53 -0500 | |
commit | a949e59f3e2125e33ce7ebe904d6a98711c1fedf (patch) | |
tree | d14c051d58677c6d57abd67ebe61fa1565bc8fe9 /widget | |
parent | 75548373a761d66df364494267c89697dda91fbe (diff) | |
download | iced-a949e59f3e2125e33ce7ebe904d6a98711c1fedf.tar.gz iced-a949e59f3e2125e33ce7ebe904d6a98711c1fedf.tar.bz2 iced-a949e59f3e2125e33ce7ebe904d6a98711c1fedf.zip |
feat: set total size of QRCode
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/qr_code.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs index 21dee6b1..6a8f5ed7 100644 --- a/widget/src/qr_code.rs +++ b/widget/src/qr_code.rs @@ -34,7 +34,7 @@ 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,11 +84,17 @@ where } /// Sets the size of the squares of the grid cell of the [`QRCode`]. - pub fn cell_size(mut self, cell_size: u16) -> Self { + pub fn cell_size(mut self, cell_size: f32) -> Self { self.cell_size = cell_size; self } + /// Sets the size of the entire [`QRCode`]. + pub fn total_size(mut self, total_size: f32) -> Self { + self.cell_size = total_size / (self.data.width + 2 * QUIET_ZONE) as f32; + self + } + /// Sets the style of the [`QRCode`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self @@ -133,8 +139,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)) } |