qr_code_styling/config/
background_options.rs1use super::{Color, Gradient};
4
5#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct BackgroundOptions {
9 pub color: Color,
11 pub gradient: Option<Gradient>,
13 pub round: f64,
15}
16
17impl Default for BackgroundOptions {
18 fn default() -> Self {
19 Self {
20 color: Color::WHITE,
21 gradient: None,
22 round: 0.0,
23 }
24 }
25}
26
27impl BackgroundOptions {
28 pub fn new(color: Color) -> Self {
30 Self {
31 color,
32 ..Default::default()
33 }
34 }
35
36 pub fn transparent() -> Self {
38 Self {
39 color: Color::TRANSPARENT,
40 gradient: None,
41 round: 0.0,
42 }
43 }
44
45 pub fn with_color(mut self, color: Color) -> Self {
47 self.color = color;
48 self
49 }
50
51 pub fn with_gradient(mut self, gradient: Gradient) -> Self {
53 self.gradient = Some(gradient);
54 self
55 }
56
57 pub fn with_round(mut self, round: f64) -> Self {
59 self.round = round.clamp(0.0, 0.5);
60 self
61 }
62}