-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel8_palette2.rs
60 lines (46 loc) · 1.44 KB
/
panel8_palette2.rs
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
extern crate kolorwheel;
use kolorwheel::{ KolorWheel, SpinMode, HslColor };
use crate::Panel;
pub struct Palette2 {
cols: u32,
rows: u32,
color: HslColor,
sat_offsets: [i32; 6],
lit_offsets: [i32; 3],
}
impl Palette2 {
pub fn new() -> Self {
Self {
cols: 3,
rows: 2,
color: HslColor::new(240, 80, 70),
sat_offsets: [60, 0, 0, 70, 0, 0],
lit_offsets: [-40, 0, 0],
}
}
}
impl Panel for Palette2 {
fn get_source_script(&self) -> &str {
file!()
}
fn paint(&mut self, ui: &mut egui::Ui) -> (KolorWheel, u32, u32) {
ui.with_layout(egui::Layout::left_to_right(egui::Align::LEFT), |ui| {
ui.label("Base hue:");
let mut h = self.color.h as i32;
ui.add(
egui::Slider::new(&mut h, 0..=359)
.orientation(egui::SliderOrientation::Vertical)
.trailing_fill(true)
.text("Hue")
.suffix("°")
);
self.color.h = h as f32;
});
let mut kw = KolorWheel::new(self.color, (self.cols * self.rows) as usize);
kw.with_hue(SpinMode::RelativeIncl(90));
kw.with_saturation(SpinMode::RelativeIncl(-20));
kw.with_saturation(SpinMode::Offset(&self.sat_offsets[0..6]));
kw.with_lightness(SpinMode::Offset(&self.lit_offsets[0..3]));
(kw, self.cols, self.rows)
}
}