iced_style/slider.rs
1//! Change the apperance of a slider.
2use crate::core::border;
3use crate::core::Color;
4
5/// The appearance of a slider.
6#[derive(Debug, Clone, Copy)]
7pub struct Appearance {
8 /// The colors of the rail of the slider.
9 pub rail: Rail,
10 /// The appearance of the [`Handle`] of the slider.
11 pub handle: Handle,
12}
13
14/// The appearance of a slider rail
15#[derive(Debug, Clone, Copy)]
16pub struct Rail {
17 /// The colors of the rail of the slider.
18 pub colors: (Color, Color),
19 /// The width of the stroke of a slider rail.
20 pub width: f32,
21 /// The border radius of the corners of the rail.
22 pub border_radius: border::Radius,
23}
24
25/// The appearance of the handle of a slider.
26#[derive(Debug, Clone, Copy)]
27pub struct Handle {
28 /// The shape of the handle.
29 pub shape: HandleShape,
30 /// The [`Color`] of the handle.
31 pub color: Color,
32 /// The border width of the handle.
33 pub border_width: f32,
34 /// The border [`Color`] of the handle.
35 pub border_color: Color,
36}
37
38/// The shape of the handle of a slider.
39#[derive(Debug, Clone, Copy)]
40pub enum HandleShape {
41 /// A circular handle.
42 Circle {
43 /// The radius of the circle.
44 radius: f32,
45 },
46 /// A rectangular shape.
47 Rectangle {
48 /// The width of the rectangle.
49 width: u16,
50 /// The border radius of the corners of the rectangle.
51 border_radius: border::Radius,
52 },
53}
54
55/// A set of rules that dictate the style of a slider.
56pub trait StyleSheet {
57 /// The supported style of the [`StyleSheet`].
58 type Style: Default;
59
60 /// Produces the style of an active slider.
61 fn active(&self, style: &Self::Style) -> Appearance;
62
63 /// Produces the style of an hovered slider.
64 fn hovered(&self, style: &Self::Style) -> Appearance;
65
66 /// Produces the style of a slider that is being dragged.
67 fn dragging(&self, style: &Self::Style) -> Appearance;
68}