qr_code_styling/config/
image_options.rs1#[derive(Debug, Clone, PartialEq)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct ImageOptions {
7 pub image_size: f64,
9 pub hide_background_dots: bool,
11 pub margin: u32,
13 pub cross_origin: Option<String>,
15 pub save_as_blob: bool,
17}
18
19impl Default for ImageOptions {
20 fn default() -> Self {
21 Self {
22 image_size: 0.4,
23 hide_background_dots: true,
24 margin: 0,
25 cross_origin: None,
26 save_as_blob: true,
27 }
28 }
29}
30
31impl ImageOptions {
32 pub fn new() -> Self {
34 Self::default()
35 }
36
37 pub fn with_image_size(mut self, size: f64) -> Self {
39 self.image_size = size.clamp(0.0, 1.0);
40 self
41 }
42
43 pub fn with_hide_background_dots(mut self, hide: bool) -> Self {
45 self.hide_background_dots = hide;
46 self
47 }
48
49 pub fn with_margin(mut self, margin: u32) -> Self {
51 self.margin = margin;
52 self
53 }
54
55 pub fn with_cross_origin(mut self, cross_origin: impl Into<String>) -> Self {
57 self.cross_origin = Some(cross_origin.into());
58 self
59 }
60
61 pub fn with_save_as_blob(mut self, save: bool) -> Self {
63 self.save_as_blob = save;
64 self
65 }
66}