Skip to main content

qr_code_styling/config/
dot_options.rs

1//! Dot styling options.
2
3use super::{Color, Gradient};
4use crate::types::DotType;
5
6/// Options for styling QR code dots.
7#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct DotsOptions {
10    /// The type/style of dots.
11    pub dot_type: DotType,
12    /// Solid color for dots (ignored if gradient is set).
13    pub color: Color,
14    /// Optional gradient for dots.
15    pub gradient: Option<Gradient>,
16    /// Whether to round dot sizes to whole pixels.
17    pub round_size: bool,
18}
19
20impl Default for DotsOptions {
21    fn default() -> Self {
22        Self {
23            dot_type: DotType::Square,
24            color: Color::BLACK,
25            gradient: None,
26            round_size: true,
27        }
28    }
29}
30
31impl DotsOptions {
32    /// Create new dots options with a specific type.
33    pub fn new(dot_type: DotType) -> Self {
34        Self {
35            dot_type,
36            ..Default::default()
37        }
38    }
39
40    /// Set the dot type.
41    pub fn with_type(mut self, dot_type: DotType) -> Self {
42        self.dot_type = dot_type;
43        self
44    }
45
46    /// Set the color.
47    pub fn with_color(mut self, color: Color) -> Self {
48        self.color = color;
49        self
50    }
51
52    /// Set the gradient.
53    pub fn with_gradient(mut self, gradient: Gradient) -> Self {
54        self.gradient = Some(gradient);
55        self
56    }
57
58    /// Set round_size option.
59    pub fn with_round_size(mut self, round_size: bool) -> Self {
60        self.round_size = round_size;
61        self
62    }
63}