Skip to main content

iced_m3/style/
scrollable.rs

1use crate::theme::ColorScheme;
2use iced::{Background, Border, Color, Shadow, widget::container};
3
4pub fn scrollable(
5    status: iced::widget::scrollable::Status,
6    theme: &impl ColorScheme,
7) -> iced::widget::scrollable::Style {
8    let color = match status {
9        iced::widget::scrollable::Status::Active {
10            is_horizontal_scrollbar_disabled: _,
11            is_vertical_scrollbar_disabled: _,
12        } => Color::TRANSPARENT,
13        iced::widget::scrollable::Status::Hovered {
14            is_horizontal_scrollbar_hovered: _,
15            is_vertical_scrollbar_hovered: _,
16            is_horizontal_scrollbar_disabled: _,
17            is_vertical_scrollbar_disabled: _,
18        } => theme.on_surface_variant().scale_alpha(0.6),
19        iced::widget::scrollable::Status::Dragged {
20            is_horizontal_scrollbar_dragged: _,
21            is_vertical_scrollbar_dragged: _,
22            is_horizontal_scrollbar_disabled: _,
23            is_vertical_scrollbar_disabled: _,
24        } => theme.on_surface_variant(),
25    };
26    iced::widget::scrollable::Style {
27        vertical_rail: iced::widget::scrollable::Rail {
28            background: Some(Background::Color(Color::TRANSPARENT)),
29            border: Border::default(),
30            scroller: iced::widget::scrollable::Scroller {
31                background: Background::Color(color),
32                border: Border::default().rounded(u32::MAX),
33            },
34        },
35        container: container::Style::default(),
36        horizontal_rail: iced::widget::scrollable::Rail {
37            background: Some(Background::Color(Color::TRANSPARENT)),
38            border: Border::default(),
39            scroller: iced::widget::scrollable::Scroller {
40                background: Background::Color(color),
41                border: Border::default().rounded(u32::MAX),
42            },
43        },
44        gap: None,
45        auto_scroll: iced::widget::scrollable::AutoScroll {
46            background: Background::Color(Color::TRANSPARENT),
47            border: Border::default(),
48            shadow: Shadow::default(),
49            icon: Color::TRANSPARENT,
50        },
51    }
52}