material_ui_rs/design/style/
slider.rs1use iced_widget::core::{Background, Color, border};
2use iced_widget::slider::{Catalog, Handle, HandleShape, Rail, Status, Style, StyleFn};
3
4use crate::Theme;
5use crate::tokens;
6
7impl Catalog for Theme {
8 type Class<'a> = StyleFn<'a, Self>;
9
10 fn default<'a>() -> <Self as Catalog>::Class<'a> {
11 Box::new(default)
12 }
13
14 fn style(&self, class: &<Self as Catalog>::Class<'_>, status: Status) -> Style {
15 class(self, status)
16 }
17}
18
19pub fn styled(left: Color, right: Color, handle_radius: f32) -> Style {
20 Style {
21 rail: Rail {
22 backgrounds: (left.into(), right.into()),
23 width: tokens::component::slider::ACTIVE_TRACK_HEIGHT,
24 border: border::rounded(tokens::component::slider::TRACK_SHAPE),
25 },
26 handle: Handle {
27 shape: HandleShape::Circle {
28 radius: handle_radius,
29 },
30 background: Background::Color(left),
31 border_width: 0.0,
32 border_color: Color::TRANSPARENT,
33 },
34 }
35}
36
37pub fn default(theme: &Theme, status: Status) -> Style {
38 let surface = theme.colors().surface;
39 let primary = theme.colors().primary;
40 let active = primary.color;
41 let inactive = surface.container.highest;
42
43 match status {
44 Status::Active | Status::Hovered | Status::Dragged => {
45 styled(active, inactive, tokens::component::slider::HANDLE_RADIUS)
46 }
47 }
48}
49
50#[cfg(test)]
51#[path = "../../../tests/design/style/slider.rs"]
52mod tests;