euv_chart/paint/struct.rs
1use super::*;
2
3/// A colour with 8 bits per channel.
4///
5/// The chart pipeline packs colours into a single `u32` (`0xRRGGBBAA`)
6/// before they reach the GPU, so the type keeps the four channels as
7/// separate bytes and does the packing once, at upload time.
8#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
9pub struct Color {
10 /// The red channel.
11 #[get(type(copy))]
12 pub red: u8,
13 /// The green channel.
14 #[get(type(copy))]
15 pub green: u8,
16 /// The blue channel.
17 #[get(type(copy))]
18 pub blue: u8,
19 /// The alpha channel, where `255` is fully opaque.
20 #[get(type(copy))]
21 pub alpha: u8,
22}
23
24/// A colour stop inside a gradient.
25#[derive(Clone, Copy, Debug, PartialEq)]
26pub struct GradientStop {
27 /// The position of the stop along the gradient, from `0.0` to `1.0`.
28 pub offset: f64,
29 /// The colour at the stop.
30 pub color: Color,
31}
32
33/// A linear colour gradient.
34#[derive(Clone, Data, Debug, PartialEq)]
35pub struct LinearGradient {
36 /// The start point, in chart coordinates.
37 pub start: (f64, f64),
38 /// The end point, in chart coordinates.
39 pub end: (f64, f64),
40 /// The colour stops, ordered by offset.
41 pub stops: Vec<GradientStop>,
42}
43
44/// A radial colour gradient.
45#[derive(Clone, Data, Debug, PartialEq)]
46pub struct RadialGradient {
47 /// The centre of the gradient, in chart coordinates.
48 pub center: (f64, f64),
49 /// The radius of the gradient, in chart pixels.
50 #[get(type(copy))]
51 pub radius: f64,
52 /// The colour stops, ordered by offset.
53 pub stops: Vec<GradientStop>,
54}
55
56/// A drop shadow applied to a filled or stroked shape.
57#[derive(Clone, Copy, Debug, PartialEq)]
58pub struct Shadow {
59 /// The horizontal offset of the shadow.
60 pub offset_x: f64,
61 /// The vertical offset of the shadow.
62 pub offset_y: f64,
63 /// The blur radius of the shadow.
64 pub blur: f64,
65 /// The colour of the shadow.
66 pub color: Color,
67}
68
69/// A text style, covering the font, the alignment, and the wrapping
70/// behaviour of a label.
71#[derive(Clone, Data, Debug, PartialEq)]
72pub struct TextStyle {
73 /// The font family list, as a CSS `font-family` value.
74 pub family: String,
75 /// The font size, in pixels.
76 #[get(type(copy))]
77 pub size: f64,
78 /// The font weight, as a CSS `font-weight` value.
79 pub weight: String,
80 /// The font style, as a CSS `font-style` value.
81 pub style: String,
82 /// The horizontal alignment of the text relative to its anchor point.
83 pub align: TextAlign,
84 /// The vertical alignment of the text relative to its anchor point.
85 pub vertical_align: TextVerticalAlign,
86 /// The line height, as a multiple of the font size.
87 #[get(type(copy))]
88 pub line_height: f64,
89 /// Whether the text wraps when it exceeds its box.
90 #[get(type(copy))]
91 pub wrap: bool,
92 /// What happens to text that does not fit.
93 pub overflow: TextOverflow,
94 /// The colour of the text.
95 pub color: Color,
96 /// The colour painted behind the text, if any.
97 #[get(skip)]
98 #[get_mut(pub(crate))]
99 #[set(pub(crate))]
100 pub background: Option<Color>,
101 /// The padding between the text and its background, in pixels.
102 pub padding: (f64, f64, f64, f64),
103 /// The border width drawn around the text, in pixels.
104 #[get(type(copy))]
105 pub border_width: f64,
106 /// The colour of the border drawn around the text.
107 #[get(skip)]
108 #[get_mut(pub(crate))]
109 #[set(pub(crate))]
110 pub border_color: Option<Color>,
111 /// The radius of the background's rounded corners, in pixels.
112 #[get(type(copy))]
113 pub border_radius: f64,
114 /// The rotation of the text, in degrees, around its anchor point.
115 #[get(type(copy))]
116 pub rotate: f64,
117 /// The stroke width of the text outline.
118 #[get(type(copy))]
119 pub stroke_width: f64,
120 /// The colour of the text outline.
121 #[get(skip)]
122 #[get_mut(pub(crate))]
123 #[set(pub(crate))]
124 pub stroke_color: Option<Color>,
125 /// The per-run style overrides, keyed by the name used in the text's
126 /// `{name|…}` markup.
127 pub rich: Vec<(String, RichTextStyle)>,
128}
129
130/// The style of one run inside a rich-text label.
131#[derive(Clone, Debug, PartialEq)]
132pub struct RichTextStyle {
133 /// The font family list, as a CSS `font-family` value.
134 pub family: Option<String>,
135 /// The font size, in pixels.
136 pub size: Option<f64>,
137 /// The font weight, as a CSS `font-weight` value.
138 pub weight: Option<String>,
139 /// The font style, as a CSS `font-style` value.
140 pub style: Option<String>,
141 /// The colour of the run.
142 pub color: Option<Color>,
143 /// The colour painted behind the run.
144 pub background: Option<Color>,
145 /// The padding between the run and its background.
146 pub padding: Option<(f64, f64, f64, f64)>,
147 /// The line height of the run, as a multiple of the font size.
148 pub line_height: Option<f64>,
149}
150
151/// The line style of a shape: its width, its caps, its joins, and its
152/// dash pattern.
153#[derive(Clone, Data, Debug, PartialEq)]
154pub struct LineStyle {
155 /// The line width, in pixels.
156 #[get(type(copy))]
157 pub width: f64,
158 /// How the ends of an open stroke are drawn.
159 pub cap: LineCap,
160 /// How the corners between segments are drawn.
161 pub join: LineJoin,
162 /// The dash pattern applied along the stroke.
163 pub dash: DashPattern,
164 /// The opacity of the stroke, from `0.0` to `1.0`.
165 #[get(type(copy))]
166 pub opacity: f64,
167 /// The shadow cast by the stroke.
168 #[get(skip)]
169 #[get_mut(pub(crate))]
170 #[set(pub(crate))]
171 pub shadow: Option<Shadow>,
172 /// The colour of the stroke.
173 pub color: Color,
174}
175
176/// A fill and a stroke, as attached to a shape in a series.
177#[derive(Clone, Debug, PartialEq)]
178pub struct ShapeStyle {
179 /// The fill of the shape.
180 pub fill: Fill,
181 /// The stroke of the shape.
182 pub stroke: Stroke,
183 /// The stroke's geometry parameters.
184 pub line_style: LineStyle,
185 /// The shadow cast by the shape.
186 pub shadow: Option<Shadow>,
187 /// The opacity of the whole shape, from `0.0` to `1.0`.
188 pub opacity: f64,
189}