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