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
#![doc = include_str!("../readme.md")]
#![allow(clippy::collapsible_else_if)]
mod scroll;
mod scroll_area;
pub use scroll::{Scroll, ScrollState, ScrollStyle};
pub use scroll_area::{ScrollArea, ScrollAreaState};
pub mod event {
use rat_event::{ConsumedEvent, Outcome};
/// Result of event-handling for a scroll.
///
/// All values are in terms of offset.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ScrollOutcome {
/// The given event has not been used at all.
Continue,
/// The event has been recognized, but the result was nil.
/// Further processing for this event may stop.
Unchanged,
/// The event has been recognized and there is some change
/// due to it.
/// Further processing for this event may stop.
/// Rendering the ui is advised.
Changed,
/// Scroll delta.
Up(usize),
/// Scroll delta.
Down(usize),
/// Scroll delta.
Left(usize),
/// Scroll delta.
Right(usize),
/// Absolute position.
VPos(usize),
/// Absolute position.
HPos(usize),
}
impl ConsumedEvent for ScrollOutcome {
fn is_consumed(&self) -> bool {
!matches!(self, ScrollOutcome::Continue)
}
}
impl From<ScrollOutcome> for Outcome {
fn from(value: ScrollOutcome) -> Self {
match value {
ScrollOutcome::Continue => Outcome::Continue,
ScrollOutcome::Unchanged => Outcome::Unchanged,
ScrollOutcome::Changed => Outcome::Changed,
ScrollOutcome::Up(_) => Outcome::Changed,
ScrollOutcome::Down(_) => Outcome::Changed,
ScrollOutcome::Left(_) => Outcome::Changed,
ScrollOutcome::Right(_) => Outcome::Changed,
ScrollOutcome::VPos(_) => Outcome::Changed,
ScrollOutcome::HPos(_) => Outcome::Changed,
}
}
}
}
///
/// Behaviour of the scrollbar.
///
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum ScrollbarPolicy {
/// Always renders the scrollbar recognizable as scrollbar.
Always,
/// If the scrollbar is not needed, it will be rendered in
/// a 'minimized' style.
///
/// If a `min_symbol` is set, the area for the scrollbar will
/// be filled with the symbol.
/// If a `min_style`is set, the area for the scrollbar will
/// be set to this style. If no min_symbol is set, this will
/// just set the style.
///
/// > The scrollbar is not needed, if `max_offset == 0`.
#[default]
Minimize,
/// If the scrollbar is not needed, no area is reserved for it.
/// The widget will get the extra area.
///
/// If the scrollbar is rendered combined with a block,
/// the block still might reserve the same space for itself.
Collapse,
}
mod _private {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonExhaustive;
}