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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use strum_macros::EnumString;
use crate::color::Color;
use crate::font::{FontFamily, FontSize, FontStyle, FontWeight};
use crate::geometry::{ByCorner, ByDirection, ByEdge, Dimension};
use crate::layout::LayoutDirection;
use crate::styles::{
Align, Border, FlexDirection, Inherited, Justify, ObjectFit, Overflow, TextAlign, Transform,
Visibility,
};
/// Determines whether this view should be included in calculating the layout of
/// descendant views of the ancestor of this view. Note: unlike the internal
/// representation of positions, this enum is shallow (like CSS) and does not
/// contain the position-dependent subfields.
#[derive(Copy, Clone, Debug, Eq, PartialEq, EnumString)]
pub enum PositionType {
/// If layed out absolutely, this view does not affect the layout of its
/// ancestor or siblings.
#[strum(serialize = "absolute")]
Absolute,
/// If layed out relatively, this view is included in calculating the layout
/// of its ancestor and siblings.
#[strum(serialize = "relative")]
Relative,
}
/// Represents a typed property value.
#[derive(Debug)]
pub enum PropertyValue {
/// This is the alignment of items along the main axis of the flexbox. The
/// default value for this property is `Align::Stretch` which will resize
/// descendant views along the cross axis to match the relevant dimension of
/// this view.
AlignItems(Align),
/// This is the background color of this view. The default color is
/// transparent. This property does not affect the layout of this view, its
/// siblings or its descendants.
BackgroundColor(Color),
/// Provides the distance of this view to the bottom edge of its ancestor.
Bottom(Dimension<f32>),
/// This is the color that will be used to fill the text outlines. If not
/// present, the Text component will inherit the text color of its parent.
/// If the parent does not have a color, the default `Color::canvastext()`
/// system color will be used. Note that the concrete value of this color
/// is system-dependent and can vary depending on the user's appearance mode
/// (i.e. light vs. dark mode).
Color(Inherited<Color>),
/// This field determines the direction in which descendant views are layed
/// out.
Direction(Inherited<LayoutDirection>),
/// If present, this property controls the weight of this view in computing
/// a layout using the flexbox algorithm.
FlexBasis(Dimension<f32>),
/// This is the main axis along which the flexbox algorithm operates.
FlexDirection(FlexDirection),
/// This property controls the priority of this view when the flexbox can
/// grow. The default value of this property is 0.0, which means that this
/// view does not grow if more space is available. If set to any non-zero
/// positive number, this view will consume (a portion of) the remaining
/// available space of a flexbox.
FlexGrow(f32),
/// This property controls the priority of this view when the flexbox is
/// shrunk. The default value of this property is 1.0, which means that this
/// view is shrunk when necessary. If set to 0.0, this view will not be
/// shrunk.
FlexShrink(f32),
/// This is the font family that will be used to render the text outlines.
/// If not present, the Text component will inherit its font family from its
/// parent. If the parent does not have a font family, the default
/// `FontFamily::Generic(GenericFontFamily::SansSerif)` will be used. Note
/// that the concrete value of this font family is system-dependent and can
/// vary depending on the user's preferred fonts.
FontFamily(Inherited<FontFamily<String>>),
/// This is the font style that will be used to render the text outlines. If
/// not present, the Text component will inherit its font style from its
/// parent. If the parent does not have a font style, the default
/// `FontStyle::Normal` will be used.
FontStyle(Inherited<FontStyle>),
/// This is the font weight that will be used to render the text outlines.
/// If not present, the Text component will inherit its font weight from its
/// parent. If the parent does not have a font weight, the default
/// `FontWeight::Normal` (400) will be used.
FontWeight(Inherited<FontWeight>),
/// This is the font size that will be used to render the text. If not
/// present, the Text component will inherit its font size from its parent.
/// If the parent does not have a font size, the default `FontSize:Medium`
/// will be used. Note that the concrete value of this font size is
/// system-dependent and can vary depending on a user's preferred font size.
FontSize(Inherited<FontSize>),
/// This is the height of the view.
Height(Dimension<f32>),
/// This property controls how the flexbox algorithm justifies content along
/// the cross axis of the flexbox. The default value for this property is
/// `Justify::FlexStart` which will stick the content to the start of the
/// main axis.
JustifyContent(Justify),
/// Provides the distance of this view to the left edge of its ancestor.
Left(Dimension<f32>),
/// This is the maximum height of this view. This must not be less than the
/// `height` field if both fields are present and contain absolute values.
MaxHeight(Dimension<f32>),
/// This is the maximum width of this view. This must not be less than the
/// `width` field if both fields are present and contain absolute values.
MaxWidth(Dimension<f32>),
/// This is the minimum height of this view. This must not be greater than
/// the `height` field if both fields are present and contain absolute
/// values.
MinHeight(Dimension<f32>),
/// This is the minimum width of this view. This must not be greater than
/// the `width` field if both fields are present and contain absolute
/// values.
MinWidth(Dimension<f32>),
/// Controls the method for fitting images that do not match the dimensions
/// of their container.
ObjectFit(ObjectFit),
/// If neither 1.0 nor 0.0, this property contains the weight of this layer
/// during composition. If 0.0, the layer is not composited at all, and if
/// 1.0, it is composited over any underlying layers. The default value is
/// 1.0.
Opacity(f32),
/// Controls the way dimensions of views are adjusted when their content
/// overflows their original boundaries.
Overflow(Overflow),
/// This property controls the margin that is used outside this view.
Margin(ByEdge<Dimension<f32>>),
/// This property controls the border that is rendered around this view.
Border(ByEdge<Border>),
/// If not 0.0, this field controls the corner radius of this view. This
/// property does not affect the layout of this view, its siblings or its
/// descendants.
BorderRadius(ByCorner<ByDirection<Dimension<f32>>>),
/// This property controls the padding that is used inside this view.
Padding(ByEdge<Dimension<f32>>),
/// This field determines whether this view should be included in
/// calculating the layout of descendant views of the ancestor of this view.
Position(PositionType),
/// Provides the distance of this view to the right edge of its ancestor.
Right(Dimension<f32>),
/// Controls the alignment of text when it is rendered to a container that
/// is larger than the rendered text.
TextAlign(Inherited<TextAlign>),
/// If present, controls the color that this image is rendered in. Only the
/// alpha channel of the original image is kept: all other channels are
/// replaced by the given tint color. If this tint color exists in a
/// different color space than the original image, the resulting image is
/// drawn using the color space of the tint color.
TintColor(Color),
/// Provides the distance of this view to the top edge of its ancestor.
Top(Dimension<f32>),
/// Applies a series of 3D affine transformations to this view.
Transform([Transform<f32>; 8]),
/// Controls the visibility of this view. Invisible views are still included
/// in layout calculations, but are not actually rendered to the screen.
/// This can be used as a performance optimization. Generally, it is more
/// efficient to set a view's visibility to hidden than to set its opacity
/// to zero.
Visibility(Visibility),
/// This is the width of the view.
Width(Dimension<f32>),
}