Skip to main content

polyhorn_ios_sys/polykit/
geometry.rs

1use crate::coregraphics::CGFloat;
2
3/// An abstract type representing a dimensional unit of measure.
4#[repr(C)]
5#[derive(Copy, Clone, Debug)]
6pub struct PLYDimension {
7    /// The unit of this dimension.
8    pub kind: PLYDimensionKind,
9
10    /// The value of this dimension.
11    pub value: CGFloat,
12}
13
14/// Represents the unit of a dimension.
15#[repr(C)]
16#[derive(Copy, Clone, Debug)]
17pub enum PLYDimensionKind {
18    /// Absolute unit of measure for display points.
19    Pixels,
20
21    /// Relative unit of measure.
22    Percentage,
23}
24
25/// A structure that contains a point in a two-dimensional coordinate system.
26#[repr(C)]
27#[derive(Copy, Clone, Debug)]
28pub struct PLYPoint {
29    /// The x-coordinate of the point.
30    pub x: PLYDimension,
31
32    /// The y-coordinate of the point.
33    pub y: PLYDimension,
34}
35
36impl PLYPoint {
37    /// Returns a point with the specified coordinates.
38    pub fn new(x: PLYDimension, y: PLYDimension) -> PLYPoint {
39        PLYPoint { x, y }
40    }
41}
42
43/// Abstract type that contains a value of the given type for each horizontal
44/// edge of a rectangle.
45#[repr(C)]
46#[derive(Copy, Clone, Debug)]
47pub struct PLYLayoutAxisX<T> {
48    /// Whether the this axis is layout direction independent or not.
49    pub independent: bool,
50
51    /// Value for the left edge or leading edge if independent is false.
52    pub start: T,
53
54    /// Value for the right edge or trailing edge if independent is false.
55    pub end: T,
56}
57
58/// An abstract type that contains a value of the given type for each vertical
59/// edge of a rectangle.
60#[repr(C)]
61#[derive(Copy, Clone, Debug)]
62pub struct PLYLayoutAxisY<T> {
63    /// Value for the top edge.
64    pub top: T,
65
66    /// Value for the bottom edge.
67    pub bottom: T,
68}
69
70/// An abstract type that contains a value of the given type for each edge of a
71/// rectangle.
72#[repr(C)]
73#[derive(Copy, Clone, Debug)]
74pub struct PLYByEdge<T> {
75    /// Values for the horizontal edges.
76    pub horizontal: PLYLayoutAxisX<T>,
77
78    /// Values for the vertical edges.
79    pub vertical: PLYLayoutAxisY<T>,
80}
81
82/// The radius to use when drawing rounded corners for a view's background.
83#[repr(C)]
84#[derive(Copy, Clone, Debug)]
85pub struct PLYCornerRadii {
86    /// The radius to use when drawing the rounded top left corner for a view's
87    /// background.
88    pub top_left: PLYPoint,
89
90    /// The radius to use when drawing the rounded top right corner for a view's
91    /// background.
92    pub top_right: PLYPoint,
93
94    /// The radius to use when drawing the rounded bottom left corner for a
95    /// view's background.
96    pub bottom_right: PLYPoint,
97
98    /// The radius to use when drawing the rounded bottom right corner for a
99    /// view's background.
100    pub bottom_left: PLYPoint,
101}
102
103/// The inset distances for views.
104#[repr(C)]
105#[derive(Copy, Clone, Debug, Default, PartialEq)]
106pub struct PLYEdgeInsets {
107    /// The top edge inset value.
108    pub top: CGFloat,
109
110    /// The left edge inset value.
111    pub left: CGFloat,
112
113    /// The bottom edge inset value.
114    pub bottom: CGFloat,
115
116    /// The right edge inset value.
117    pub right: CGFloat,
118}