Skip to main content

qr_code_styling/config/
corner_options.rs

1//! Corner styling options.
2
3use super::{Color, Gradient};
4use crate::types::{CornerSquareType, CornerDotType};
5
6/// Options for styling QR code corner squares (finder patterns).
7#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct CornersSquareOptions {
10    /// The type/style of corner squares.
11    pub square_type: CornerSquareType,
12    /// Solid color for corner squares (ignored if gradient is set).
13    pub color: Color,
14    /// Optional gradient for corner squares.
15    pub gradient: Option<Gradient>,
16}
17
18impl Default for CornersSquareOptions {
19    fn default() -> Self {
20        Self {
21            square_type: CornerSquareType::Square,
22            color: Color::BLACK,
23            gradient: None,
24        }
25    }
26}
27
28impl CornersSquareOptions {
29    /// Create new corner square options with a specific type.
30    pub fn new(square_type: CornerSquareType) -> Self {
31        Self {
32            square_type,
33            ..Default::default()
34        }
35    }
36
37    /// Set the square type.
38    pub fn with_type(mut self, square_type: CornerSquareType) -> Self {
39        self.square_type = square_type;
40        self
41    }
42
43    /// Set the color.
44    pub fn with_color(mut self, color: Color) -> Self {
45        self.color = color;
46        self
47    }
48
49    /// Set the gradient.
50    pub fn with_gradient(mut self, gradient: Gradient) -> Self {
51        self.gradient = Some(gradient);
52        self
53    }
54}
55
56/// Options for styling QR code corner dots (center of finder patterns).
57#[derive(Debug, Clone, PartialEq)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct CornersDotOptions {
60    /// The type/style of corner dots.
61    pub dot_type: CornerDotType,
62    /// Solid color for corner dots (ignored if gradient is set).
63    pub color: Color,
64    /// Optional gradient for corner dots.
65    pub gradient: Option<Gradient>,
66}
67
68impl Default for CornersDotOptions {
69    fn default() -> Self {
70        Self {
71            dot_type: CornerDotType::Dot,
72            color: Color::BLACK,
73            gradient: None,
74        }
75    }
76}
77
78impl CornersDotOptions {
79    /// Create new corner dot options with a specific type.
80    pub fn new(dot_type: CornerDotType) -> Self {
81        Self {
82            dot_type,
83            ..Default::default()
84        }
85    }
86
87    /// Set the dot type.
88    pub fn with_type(mut self, dot_type: CornerDotType) -> Self {
89        self.dot_type = dot_type;
90        self
91    }
92
93    /// Set the color.
94    pub fn with_color(mut self, color: Color) -> Self {
95        self.color = color;
96        self
97    }
98
99    /// Set the gradient.
100    pub fn with_gradient(mut self, gradient: Gradient) -> Self {
101        self.gradient = Some(gradient);
102        self
103    }
104}