iced_plot/
reference_lines.rs1use crate::{Color, LineStyle};
2
3#[derive(Debug, Clone)]
5pub struct VLine {
6 pub x: f64,
8 pub label: Option<String>,
10 pub color: Color,
12 pub width: f32,
14 pub line_style: LineStyle,
16}
17
18impl VLine {
19 pub fn new(x: f64) -> Self {
21 Self {
22 x,
23 label: None,
24 color: Color::from_rgb(0.5, 0.5, 0.5),
25 width: 1.0,
26 line_style: LineStyle::Solid,
27 }
28 }
29
30 pub fn with_label(mut self, label: impl Into<String>) -> Self {
32 let l = label.into();
33 if !l.is_empty() {
34 self.label = Some(l);
35 }
36 self
37 }
38
39 pub fn with_color(mut self, color: Color) -> Self {
41 self.color = color;
42 self
43 }
44
45 pub fn with_width(mut self, width: f32) -> Self {
47 self.width = width.max(0.5);
48 self
49 }
50
51 pub fn with_style(mut self, style: LineStyle) -> Self {
53 self.line_style = style;
54 self
55 }
56}
57
58#[derive(Debug, Clone)]
60pub struct HLine {
61 pub y: f64,
63 pub label: Option<String>,
65 pub color: Color,
67 pub width: f32,
69 pub line_style: LineStyle,
71}
72
73impl HLine {
74 pub fn new(y: f64) -> Self {
76 Self {
77 y,
78 label: None,
79 color: Color::from_rgb(0.5, 0.5, 0.5),
80 width: 1.0,
81 line_style: LineStyle::Solid,
82 }
83 }
84
85 pub fn with_label(mut self, label: impl Into<String>) -> Self {
87 let l = label.into();
88 if !l.is_empty() {
89 self.label = Some(l);
90 }
91 self
92 }
93
94 pub fn with_color(mut self, color: Color) -> Self {
96 self.color = color;
97 self
98 }
99
100 pub fn with_width(mut self, width: f32) -> Self {
102 self.width = width.max(0.5);
103 self
104 }
105
106 pub fn with_style(mut self, style: LineStyle) -> Self {
108 self.line_style = style;
109 self
110 }
111}