iced_core/
alignment.rs

1//! Align and position widgets.
2
3/// Alignment on the axis of a container.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum Alignment {
6    /// Align at the start of the axis.
7    Start,
8
9    /// Align at the center of the axis.
10    Center,
11
12    /// Align at the end of the axis.
13    End,
14}
15
16impl From<Horizontal> for Alignment {
17    fn from(horizontal: Horizontal) -> Self {
18        match horizontal {
19            Horizontal::Left => Self::Start,
20            Horizontal::Center => Self::Center,
21            Horizontal::Right => Self::End,
22        }
23    }
24}
25
26impl From<Vertical> for Alignment {
27    fn from(vertical: Vertical) -> Self {
28        match vertical {
29            Vertical::Top => Self::Start,
30            Vertical::Center => Self::Center,
31            Vertical::Bottom => Self::End,
32        }
33    }
34}
35
36/// The horizontal [`Alignment`] of some resource.
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub enum Horizontal {
39    /// Align left
40    Left,
41
42    /// Horizontally centered
43    Center,
44
45    /// Align right
46    Right,
47}
48
49impl From<Alignment> for Horizontal {
50    fn from(alignment: Alignment) -> Self {
51        match alignment {
52            Alignment::Start => Self::Left,
53            Alignment::Center => Self::Center,
54            Alignment::End => Self::Right,
55        }
56    }
57}
58
59/// The vertical [`Alignment`] of some resource.
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
61pub enum Vertical {
62    /// Align top
63    Top,
64
65    /// Vertically centered
66    Center,
67
68    /// Align bottom
69    Bottom,
70}
71
72impl From<Alignment> for Vertical {
73    fn from(alignment: Alignment) -> Self {
74        match alignment {
75            Alignment::Start => Self::Top,
76            Alignment::Center => Self::Center,
77            Alignment::End => Self::Bottom,
78        }
79    }
80}