polyhorn_ui/styles/position.rs
1use crate::geometry::{ByEdge, Dimension};
2
3/// Controls the absolute positioning of a view.
4#[derive(Copy, Clone, Debug, Default, PartialEq)]
5pub struct Absolute {
6 /// Provides the distance of this view to each of the edges of its ancestor.
7 pub distances: ByEdge<Dimension<f32>>,
8}
9
10/// Controls the relative positioning of a view.
11#[derive(Copy, Clone, Debug, PartialEq)]
12pub struct Relative {
13 /// If present, this property controls the weight of this view in computing
14 /// a layout using the flexbox algorithm.
15 pub flex_basis: Dimension<f32>,
16
17 /// This property controls the priority of this view when the flexbox can
18 /// grow. The default value of this property is 0.0, which means that this
19 /// view does not grow if more space is available. If set to any non-zero
20 /// positive number, this view will consume (a portion of) the remaining
21 /// available space of a flexbox.
22 pub flex_grow: f32,
23
24 /// This property controls the priority of this view when the flexbox is
25 /// shrunk. The default value of this property is 1.0, which means that this
26 /// view is shrunk when necessary. If set to 0.0, this view will not be
27 /// shrunk.
28 pub flex_shrink: f32,
29}
30
31impl Default for Relative {
32 fn default() -> Self {
33 Relative {
34 flex_basis: Dimension::Undefined,
35 flex_grow: 0.0,
36 flex_shrink: 1.0,
37 }
38 }
39}
40
41/// Determines whether a view affects the layout of its ancestor and siblings.
42#[derive(Copy, Clone, Debug, PartialEq)]
43pub enum Position {
44 /// If layed out absolutely, this view does not affect the layout of its
45 /// ancestor or siblings.
46 Absolute(Absolute),
47
48 /// If layed out relatively, this view is included in calculating the layout
49 /// of its ancestor and siblings.
50 Relative(Relative),
51}