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
37impl VerticalValueAlignment {
38    /// Convert to ratatui's Alignment
39    pub fn to_ratatui_alignment(&self) -> ratatui::layout::Alignment {
40        match self {
41            VerticalValueAlignment::Left => ratatui::layout::Alignment::Left,
42            VerticalValueAlignment::Center => ratatui::layout::Alignment::Center,
43            VerticalValueAlignment::Right => ratatui::layout::Alignment::Right,
44        }
45    }
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_vertical_label_position_default() {
54        assert_eq!(VerticalLabelPosition::default(), VerticalLabelPosition::Top);
55    }
56
57    #[test]
58    fn test_vertical_value_position_default() {
59        assert_eq!(
60            VerticalValuePosition::default(),
61            VerticalValuePosition::Bottom
62        );
63    }
64
65    #[test]
66    fn test_vertical_value_alignment_default() {
67        assert_eq!(
68            VerticalValueAlignment::default(),
69            VerticalValueAlignment::Center
70        );
71    }
72
73    #[test]
74    fn test_vertical_value_alignment_conversion() {
75        use ratatui::layout::Alignment;
76
77        assert_eq!(
78            VerticalValueAlignment::Left.to_ratatui_alignment(),
79            Alignment::Left
80        );
81        assert_eq!(
82            VerticalValueAlignment::Center.to_ratatui_alignment(),
83            Alignment::Center
84        );
85        assert_eq!(
86            VerticalValueAlignment::Right.to_ratatui_alignment(),
87            Alignment::Right
88        );
89    }
90}