winio_primitive/
drawing.rs

1use euclid::*;
2use rgb::RGBA8;
3
4/// The logical space.
5pub struct LogicalSpace;
6
7/// Logical point.
8pub type Point = Point2D<f64, LogicalSpace>;
9/// Logical vector.
10pub type Vector = Vector2D<f64, LogicalSpace>;
11/// Logical size.
12pub type Size = Size2D<f64, LogicalSpace>;
13/// Logical rectangle.
14pub type Rect = euclid::Rect<f64, LogicalSpace>;
15/// Logical rectangle box.
16pub type RectBox = Box2D<f64, LogicalSpace>;
17/// Logical margin.
18pub type Margin = SideOffsets2D<f64, LogicalSpace>;
19/// Logical rotation.
20pub type Rotation = Rotation2D<f64, LogicalSpace, LogicalSpace>;
21/// Angle of vector.
22pub type Angle = euclid::Angle<f64>;
23
24/// The relative space, which maps [0.0, 1.0] to the logical space.
25pub struct RelativeSpace;
26
27/// Relative point.
28pub type RelativePoint = Point2D<f64, RelativeSpace>;
29/// Relative vector.
30pub type RelativeVector = Vector2D<f64, RelativeSpace>;
31/// Relative size.
32pub type RelativeSize = Size2D<f64, RelativeSpace>;
33
34/// Transform from the relative space to the logical space.
35pub type RelativeToLogical = Transform2D<f64, RelativeSpace, LogicalSpace>;
36
37/// Color theme of application.
38#[derive(Debug, PartialEq, Eq, Clone, Copy)]
39#[non_exhaustive]
40pub enum ColorTheme {
41    /// Default light theme.
42    Light,
43    /// Dark theme.
44    Dark,
45}
46
47/// Orientation.
48#[derive(Debug, PartialEq, Eq, Clone, Copy)]
49pub enum Orient {
50    /// Horizontal orientation.
51    Horizontal,
52    /// Vertical orientation.
53    Vertical,
54}
55
56/// Horizontal alignment.
57#[derive(Debug, PartialEq, Eq, Clone, Copy)]
58pub enum HAlign {
59    /// Left aligned.
60    Left,
61    /// Horizontal centered.
62    Center,
63    /// Right aligned.
64    Right,
65    /// Fill the horizontal space.
66    Stretch,
67}
68
69/// Vertical alignment.
70#[derive(Debug, PartialEq, Eq, Clone, Copy)]
71pub enum VAlign {
72    /// Top aligned.
73    Top,
74    /// Vertical centered.
75    Center,
76    /// Bottom aligned.
77    Bottom,
78    /// Fill the vertical space.
79    Stretch,
80}
81
82/// Color type.
83pub type Color = RGBA8;
84
85/// Font for drawing.
86#[derive(Debug, Clone)]
87pub struct DrawingFont {
88    /// Font name.
89    pub family: String,
90    /// Font size.
91    pub size: f64,
92    /// *Italic*.
93    pub italic: bool,
94    /// **Bold**.
95    pub bold: bool,
96    /// Horizontal alignment.
97    pub halign: HAlign,
98    /// Vertical alignment.
99    pub valign: VAlign,
100}
101
102impl DrawingFont {
103    /// Create a builder.
104    pub fn builder() -> DrawingFontBuilder {
105        DrawingFontBuilder::new()
106    }
107}
108
109/// Builder of [`DrawingFont`].
110pub struct DrawingFontBuilder {
111    value: DrawingFont,
112}
113
114impl Default for DrawingFontBuilder {
115    fn default() -> Self {
116        Self {
117            value: DrawingFont {
118                family: String::new(),
119                size: 0.0,
120                italic: false,
121                bold: false,
122                halign: HAlign::Left,
123                valign: VAlign::Top,
124            },
125        }
126    }
127}
128
129impl DrawingFontBuilder {
130    /// Create a builder for [`DrawingFont`].
131    pub fn new() -> Self {
132        Self::default()
133    }
134
135    /// Font name.
136    pub fn family(&mut self, s: impl AsRef<str>) -> &mut Self {
137        self.value.family = s.as_ref().to_string();
138        self
139    }
140
141    /// Font size.
142    pub fn size(&mut self, s: f64) -> &mut Self {
143        self.value.size = s;
144        self
145    }
146
147    /// *Italic*.
148    pub fn italic(&mut self, v: bool) -> &mut Self {
149        self.value.italic = v;
150        self
151    }
152
153    /// **Bold**.
154    pub fn bold(&mut self, v: bool) -> &mut Self {
155        self.value.bold = v;
156        self
157    }
158
159    /// Horizontal alignment.
160    pub fn halign(&mut self, v: HAlign) -> &mut Self {
161        self.value.halign = v;
162        self
163    }
164
165    /// Vertical alignment.
166    pub fn valign(&mut self, v: VAlign) -> &mut Self {
167        self.value.valign = v;
168        self
169    }
170
171    /// Build [`DrawingFont`].
172    pub fn build(&self) -> DrawingFont {
173        self.value.clone()
174    }
175}
176
177/// Represents the mouse button.
178#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
179pub enum MouseButton {
180    /// Left button.
181    Left,
182    /// Right button.
183    Right,
184    /// Middle button.
185    Middle,
186    /// Other buttons.
187    Other,
188}