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
//! Layouting types.

#![warn(missing_copy_implementations)]

/// Group layout type. This defines how subgroups are arranged inside of a group.
#[derive(Copy, Clone, PartialEq)]
pub enum Layout {
    /// The layout for individual subgroups is defined by the user via `ui.set_cursor(x, y)`.
    Freeform,
    /// Subgroups are laid out horizontally, from left to right. The default starting point for layout is the upper-left
    /// corner of the group.
    Horizontal,
    /// Subgroups are laid out vertically, from top to bottom. The default starting point for layout is the upper-left
    /// corner of the group.
    Vertical,
    /// Subgroups are laid out horizontally, from right to left. The default starting point for layout is the
    /// upper-right corner of the group.
    HorizontalRev,
    /// Subgroups are laid out vertically, from bottom to top. The default starting point for layout is the
    /// lower-left corner of the group.
    VerticalRev,
}

/// Horizontal alignment position.
#[derive(Copy, Clone, PartialEq)]
pub enum AlignH {
    Left,
    Center,
    Right,
}

/// Vertical alignment position.
#[derive(Copy, Clone, PartialEq)]
pub enum AlignV {
    Top,
    Middle,
    Bottom,
}

pub use AlignH::*;
pub use AlignV::*;

/// Alignment type. This is used in `ui.align(alignment)` and text rendering.
pub type Alignment = (AlignH, AlignV);

/// Convenience const for `(Center, Middle)` alignment.
pub const CENTER: Alignment = (Center, Middle);

/// Padding amounts.
///
/// Usually you don't need to construct this directly, as this implements From for several types, and paws
/// accepts `impl Into<Padding>` instead of just `Padding` in all functions.
#[derive(Copy, Clone, PartialEq)]
pub struct Padding {
    pub right: f32,
    pub bottom: f32,
    pub left: f32,
    pub top: f32,
}

impl Padding {
    /// Creates padding from horizontal and vertical amounts. This is equivalent constructing
    /// the padding where `right` and `left` are set to `horizontal`, and `bottom` and `top` are
    /// set to `vertical`.
    pub fn hv(horizontal: f32, vertical: f32) -> Self {
        Self {
            right: horizontal,
            bottom: vertical,
            left: horizontal,
            top: vertical,
        }
    }

    /// Creates an even amount of padding for all sides.
    pub fn even(amount: f32) -> Self {
        Self {
            right: amount,
            bottom: amount,
            left: amount,
            top: amount,
        }
    }

    /// Creates the given amount of right padding. All other sides are set to `0.0`.
    pub fn right(amount: f32) -> Self {
        Self {
            right: amount,
            ..Self::default()
        }
    }

    /// Creates the given amount of bottom padding. All other sides are set to `0.0`.
    pub fn bottom(amount: f32) -> Self {
        Self {
            bottom: amount,
            ..Self::default()
        }
    }

    /// Creates the given amount of left padding. All other sides are set to `0.0`.
    pub fn left(amount: f32) -> Self {
        Self {
            left: amount,
            ..Self::default()
        }
    }

    /// Creates the given amount of top padding. All other sides are set to `0.0`.
    pub fn top(amount: f32) -> Self {
        Self {
            top: amount,
            ..Self::default()
        }
    }
}

impl Default for Padding {
    /// The default amount of padding is `0.0` for all sides.
    fn default() -> Self {
        Self {
            right: 0.0,
            bottom: 0.0,
            left: 0.0,
            top: 0.0,
        }
    }
}

impl From<(f32, f32)> for Padding {
    /// Creates padding from horizontal and vertical amounts. This is the same as calling
    /// `Padding::hv(horizontal, vertical)`.
    fn from((horizontal, vertical): (f32, f32)) -> Self {
        Self::hv(horizontal, vertical)
    }
}

impl From<f32> for Padding {
    /// Creates the given amount of padding for all sides. This is the same as calling `Padding::even(amount)`.
    fn from(amount: f32) -> Self {
        Self::even(amount)
    }
}