rat_scrolled/
lib.rs

1#![doc = include_str!("../readme.md")]
2//
3#![allow(clippy::collapsible_else_if)]
4
5mod scroll;
6mod scroll_area;
7
8pub use scroll::{
9    Scroll, ScrollState, ScrollStyle, ScrollSymbols, SCROLLBAR_DOUBLE_HORIZONTAL,
10    SCROLLBAR_DOUBLE_VERTICAL, SCROLLBAR_HORIZONTAL, SCROLLBAR_VERTICAL,
11};
12pub use scroll_area::{ScrollArea, ScrollAreaState};
13
14pub mod event {
15    use rat_event::*;
16
17    /// Result of event-handling for a scroll.
18    ///
19    /// All values are in terms of offset.
20    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
21    pub enum ScrollOutcome {
22        /// The given event has not been used at all.
23        Continue,
24        /// The event has been recognized, but the result was nil.
25        /// Further processing for this event may stop.
26        Unchanged,
27        /// The event has been recognized and there is some change
28        /// due to it.
29        /// Further processing for this event may stop.
30        /// Rendering the ui is advised.
31        Changed,
32        /// Scroll delta.
33        Up(usize),
34        /// Scroll delta.
35        Down(usize),
36        /// Scroll delta.
37        Left(usize),
38        /// Scroll delta.
39        Right(usize),
40        /// Absolute position.
41        VPos(usize),
42        /// Absolute position.
43        HPos(usize),
44    }
45
46    impl ConsumedEvent for ScrollOutcome {
47        fn is_consumed(&self) -> bool {
48            !matches!(self, ScrollOutcome::Continue)
49        }
50    }
51
52    impl From<ScrollOutcome> for Outcome {
53        fn from(value: ScrollOutcome) -> Self {
54            match value {
55                ScrollOutcome::Continue => Outcome::Continue,
56                ScrollOutcome::Unchanged => Outcome::Unchanged,
57                ScrollOutcome::Changed => Outcome::Changed,
58                ScrollOutcome::Up(_) => Outcome::Changed,
59                ScrollOutcome::Down(_) => Outcome::Changed,
60                ScrollOutcome::Left(_) => Outcome::Changed,
61                ScrollOutcome::Right(_) => Outcome::Changed,
62                ScrollOutcome::VPos(_) => Outcome::Changed,
63                ScrollOutcome::HPos(_) => Outcome::Changed,
64            }
65        }
66    }
67}
68
69///
70/// Behaviour of the scrollbar.
71///
72#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
73pub enum ScrollbarPolicy {
74    /// Always renders the scrollbar recognizable as scrollbar.
75    Always,
76
77    /// If the scrollbar is not needed, it will be rendered in
78    /// a 'minimized' style.
79    ///
80    /// If a `min_symbol` is set, the area for the scrollbar will
81    /// be filled with the symbol.
82    /// If a `min_style`is set, the area for the scrollbar will
83    /// be set to this style. If no min_symbol is set, this will
84    /// just set the style.
85    ///
86    /// > The scrollbar is not needed, if `max_offset == 0`.
87    #[default]
88    Minimize,
89
90    /// If the scrollbar is not needed, no area is reserved for it.
91    /// The widget will get the extra area.
92    ///
93    /// If the scrollbar is rendered combined with a block,
94    /// the block still might reserve the same space for itself.
95    Collapse,
96}
97
98mod _private {
99    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
100    pub struct NonExhaustive;
101}