audio_processor_iced_design_system/
knob.rs

1// Augmented Audio: Audio libraries and applications
2// Copyright (c) 2022 Pedro Tacla Yamada
3//
4// The MIT License (MIT)
5//
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22// THE SOFTWARE.
23pub use iced_audio::Knob;
24
25pub mod style {
26    use iced_audio::graphics::knob::{Appearance, NotchShape, StyleLength};
27    use iced_audio::knob::ValueArcAppearance;
28    use iced_style::Theme;
29
30    use crate::colors::Colors;
31
32    pub struct Knob;
33
34    impl iced_audio::knob::StyleSheet for Knob {
35        type Style = Theme;
36
37        fn active(&self, _style: &Self::Style) -> Appearance {
38            Appearance::Arc(iced_audio::style::knob::ArcAppearance {
39                width: StyleLength::Fixed(3.),
40                empty_color: Colors::background_level0(),
41                filled_color: Colors::active_border_color(),
42                notch: Knob::notch(),
43                cap: Default::default(),
44            })
45        }
46
47        fn hovered(&self, _style: &Self::Style) -> Appearance {
48            Appearance::Arc(iced_audio::style::knob::ArcAppearance {
49                width: StyleLength::Fixed(3.),
50                empty_color: Colors::background_level0(),
51                filled_color: Colors::active_border_color(),
52                notch: Knob::notch(),
53                cap: Default::default(),
54            })
55        }
56
57        fn dragging(&self, _style: &Self::Style) -> Appearance {
58            Appearance::Arc(iced_audio::style::knob::ArcAppearance {
59                width: StyleLength::Fixed(3.),
60                empty_color: Colors::background_level0(),
61                filled_color: Colors::active_border_color(),
62                notch: Knob::notch(),
63                cap: Default::default(),
64            })
65        }
66
67        fn value_arc_appearance(&self, _style: &Self::Style) -> Option<ValueArcAppearance> {
68            Some(ValueArcAppearance {
69                width: 1.0,
70                offset: 0.0,
71                empty_color: Some(Colors::background_level0()),
72                left_filled_color: Default::default(),
73                right_filled_color: None,
74                cap: Default::default(),
75            })
76        }
77    }
78
79    impl Knob {
80        fn notch() -> NotchShape {
81            NotchShape::Line(iced_audio::style::knob::LineNotch {
82                color: Colors::background_level0(),
83                width: StyleLength::Scaled(0.1),
84                length: StyleLength::Scaled(0.4),
85                cap: Default::default(),
86                offset: StyleLength::Fixed(0.),
87            })
88        }
89    }
90}