dioxus_leaflet/types/
path_options.rs1use serde::{Deserialize, Serialize};
2use color::{OpaqueColor, Srgb};
3
4pub type Color = OpaqueColor<Srgb>;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum LineCap {
9 Butt,
10 Round,
11 Square,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15#[serde(rename_all = "lowercase")]
16pub enum LineJoin {
17 Arcs,
18 Bevel,
19 Miter,
20 #[serde(rename = "miter-clip")]
21 MiterClip,
22 Round,
23}
24
25#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct PathOptions {
28 pub stroke: bool,
30
31 #[serde(with = "color_format")]
33 pub color: Color,
34
35 pub weight: u32,
37
38 pub opacity: f32,
40
41 pub line_cap: LineCap,
43
44 pub line_join: LineJoin,
46
47 pub fill: bool,
49
50 #[serde(with = "color_format")]
52 pub fill_color: Color,
53
54 pub fill_opacity: f32,
56}
57
58impl Default for PathOptions {
59 fn default() -> Self {
60 Self {
61 stroke: true,
62 color: Color::from_rgb8(0x33, 0x88, 0xff),
63 weight: 3,
64 opacity: 1.0,
65 line_cap: LineCap::Round,
66 line_join: LineJoin::Round,
67 fill: true,
68 fill_color: Color::from_rgb8(0x33, 0x88, 0xff),
69 fill_opacity: 0.2,
70 }
71 }
72}
73
74mod color_format {
75 use super::Color;
76 use serde::{Deserializer, Serializer};
77
78 pub fn serialize<S>(color: &Color, serializer: S) -> Result<S::Ok, S::Error>
79 where S : Serializer {
80 let color = color.to_rgba8();
81 serializer.serialize_str(&format!("rgb({r}, {g}, {b})",
82 r = color.r,
83 g = color.g,
84 b = color.b))
85 }
86
87 pub fn deserialize<'de, D>(_: D) -> Result<Color, D::Error>
88 where D : Deserializer<'de> {
89 panic!("Deserializing colors not (yet) supported")
90 }
91}