gmaps_static/
marker_style.rs1use crate::{Color, MarkerLabel, MarkerSize};
2use std::fmt;
3
4#[derive(Clone)]
5pub struct MarkerStyle {
6 size: Option<&'static MarkerSize>,
7 color: Option<&'static Color>,
8 label: Option<MarkerLabel>,
9}
10
11impl MarkerStyle {
12 pub fn new() -> Self {
13 MarkerStyle {
14 size: None,
15 color: None,
16 label: None,
17 }
18 }
19
20 pub fn size(&self, size: &'static MarkerSize) -> Self {
21 MarkerStyle {
22 size: Some(size),
23 ..(*self).clone()
24 }
25 }
26
27 pub fn color(&self, color: &'static Color) -> Self {
28 MarkerStyle {
29 color: Some(color),
30 ..(*self).clone()
31 }
32 }
33
34 pub fn label(&self, label: MarkerLabel) -> Self {
35 MarkerStyle {
36 label: Some(label),
37 ..(*self).clone()
38 }
39 }
40}
41
42impl Default for MarkerStyle {
43 fn default() -> Self {
44 MarkerStyle::new()
45 }
46}
47
48impl fmt::Display for MarkerStyle {
49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 let mut parts: Vec<String> = vec![];
51
52 if let Some(size) = &self.size {
53 parts.push(format!("size:{}", size))
54 }
55
56 if let Some(color) = &self.color {
57 parts.push(format!("color:{}", color));
58 }
59
60 if let Some(label) = &self.label {
61 parts.push(format!("label:{}", label))
62 }
63
64 write!(f, "{}", parts.join("|"))
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use crate::{BLUE, MID};
71
72 use super::*;
73
74 #[test]
75 fn it_builds_a_complete_style() {
76 let style = MarkerStyle::new().color(BLUE).label('C'.into()).size(MID);
77 assert_eq!("size:mid|color:blue|label:C", style.to_string());
78 }
79}