1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::Drawable;
/// Capability for configuring a fixed aspect ratio on node.
pub trait AspectRatio: Drawable {
/// Square aspect ratio of 1:1.
const SQUARE: f32 = 1.0;
/// A 3:2 aspect ratio.
const THREE_TWO: f32 = 3.0 / 2.0;
/// A 4:3 aspect ratio.
const FOUR_THREE: f32 = 4.0 / 3.0;
/// A 16:9 aspect ratio.
const SIXTEEN_NINE: f32 = 16.0 / 9.0;
/// A 9:16 aspect ratio.
const NINE_SIXTEEN: f32 = 9.0 / 16.0;
/// Sets an aspect ratio on the node.
///
/// # Arguments
/// - `value`: The aspect ratio expressed as width divided by height.
///
/// # Returns
/// - [`Self`]
fn aspect_ratio<T>(mut self, value: T) -> Self
where
T: Into<Option<f32>>,
{
self.layout_mut().aspect_ratio = value.into();
self
}
/// Sets the aspect ratio to `1:1`.
///
/// # Returns
/// - [`Self`]
fn aspect_square(self) -> Self {
self.aspect_ratio(Self::SQUARE)
}
/// Sets the aspect ratio to `3:2`.
///
/// # Returns
/// - [`Self`]
fn aspect_three_two(self) -> Self {
self.aspect_ratio(Self::THREE_TWO)
}
/// Sets the aspect ratio to `4:3`.
///
/// # Returns
/// - [`Self`]
fn aspect_four_three(self) -> Self {
self.aspect_ratio(Self::FOUR_THREE)
}
/// Sets the aspect ratio to `16:9`.
///
/// # Returns
/// - [`Self`]
fn aspect_sixteen_nine(self) -> Self {
self.aspect_ratio(Self::SIXTEEN_NINE)
}
/// Sets the aspect ratio to `9:16`.
///
/// # Returns
/// - [`Self`]
fn aspect_nine_sixteen(self) -> Self {
self.aspect_ratio(Self::NINE_SIXTEEN)
}
}