Skip to main content

tui_slider/
position.rs

1//! Position enums for label and value placement in sliders
2
3/// Position of the label in a vertical slider
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum VerticalLabelPosition {
6    /// Label at the top of the slider
7    #[default]
8    Top,
9    /// Label at the bottom of the slider
10    Bottom,
11}
12
13/// Vertical position of the value display in a vertical slider
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
15pub enum VerticalValuePosition {
16    /// Value at the top
17    Top,
18    /// Value at the middle
19    Middle,
20    /// Value at the bottom
21    #[default]
22    Bottom,
23}
24
25/// Horizontal alignment of the value text in a vertical slider
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
27pub enum VerticalValueAlignment {
28    /// Value aligned to the left
29    Left,
30    /// Value aligned to the center
31    #[default]
32    Center,
33    /// Value aligned to the right
34    Right,
35}
36
37/// Vertical alignment of the bar in a horizontal slider
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
39pub enum HorizontalBarAlignment {
40    /// Bar at the top of the area
41    Top,
42    /// Bar at the center (middle) of the area
43    #[default]
44    Center,
45    /// Bar at the bottom of the area
46    Bottom,
47}
48
49impl VerticalValueAlignment {
50    /// Convert to ratatui's Alignment
51    pub fn to_ratatui_alignment(&self) -> ratatui::layout::Alignment {
52        match self {
53            VerticalValueAlignment::Left => ratatui::layout::Alignment::Left,
54            VerticalValueAlignment::Center => ratatui::layout::Alignment::Center,
55            VerticalValueAlignment::Right => ratatui::layout::Alignment::Right,
56        }
57    }
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_vertical_label_position_default() {
66        assert_eq!(VerticalLabelPosition::default(), VerticalLabelPosition::Top);
67    }
68
69    #[test]
70    fn test_vertical_value_position_default() {
71        assert_eq!(
72            VerticalValuePosition::default(),
73            VerticalValuePosition::Bottom
74        );
75    }
76
77    #[test]
78    fn test_vertical_value_alignment_default() {
79        assert_eq!(
80            VerticalValueAlignment::default(),
81            VerticalValueAlignment::Center
82        );
83    }
84
85    #[test]
86    fn test_vertical_value_alignment_conversion() {
87        use ratatui::layout::Alignment;
88
89        assert_eq!(
90            VerticalValueAlignment::Left.to_ratatui_alignment(),
91            Alignment::Left
92        );
93        assert_eq!(
94            VerticalValueAlignment::Center.to_ratatui_alignment(),
95            Alignment::Center
96        );
97        assert_eq!(
98            VerticalValueAlignment::Right.to_ratatui_alignment(),
99            Alignment::Right
100        );
101    }
102
103    #[test]
104    fn test_horizontal_bar_alignment_default() {
105        assert_eq!(
106            HorizontalBarAlignment::default(),
107            HorizontalBarAlignment::Center
108        );
109    }
110}