winio_primitive/
canvas.rs1use crate::{Color, RelativePoint, RelativeSize};
2
3#[derive(Debug, Clone)]
5pub struct SolidColorBrush {
6 pub color: Color,
8}
9
10impl SolidColorBrush {
11 pub fn new(color: Color) -> Self {
13 Self { color }
14 }
15}
16
17#[derive(Debug, PartialEq, Clone, Copy)]
19pub struct GradientStop {
20 pub color: Color,
22 pub pos: f64,
24}
25
26impl GradientStop {
27 pub fn new(color: Color, pos: f64) -> Self {
29 Self { color, pos }
30 }
31}
32
33impl From<(Color, f64)> for GradientStop {
34 fn from((color, pos): (Color, f64)) -> Self {
35 Self::new(color, pos)
36 }
37}
38
39#[derive(Debug, Clone)]
41pub struct LinearGradientBrush {
42 pub stops: Vec<GradientStop>,
44 pub start: RelativePoint,
46 pub end: RelativePoint,
48}
49
50impl LinearGradientBrush {
51 pub fn new(
53 stops: impl IntoIterator<Item = GradientStop>,
54 start: RelativePoint,
55 end: RelativePoint,
56 ) -> Self {
57 Self {
58 stops: stops.into_iter().collect(),
59 start,
60 end,
61 }
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct RadialGradientBrush {
68 pub stops: Vec<GradientStop>,
70 pub origin: RelativePoint,
72 pub center: RelativePoint,
74 pub radius: RelativeSize,
76}
77
78impl RadialGradientBrush {
79 pub fn new(
81 stops: impl IntoIterator<Item = GradientStop>,
82 origin: RelativePoint,
83 center: RelativePoint,
84 radius: RelativeSize,
85 ) -> Self {
86 Self {
87 stops: stops.into_iter().collect(),
88 origin,
89 center,
90 radius,
91 }
92 }
93}
94
95#[derive(Debug, Clone)]
97pub struct BrushPen<B> {
98 pub brush: B,
100 pub width: f64,
102}
103
104impl<B> BrushPen<B> {
105 pub fn new(brush: B, width: f64) -> Self {
107 Self { brush, width }
108 }
109}