use chrono::Timelike;
pub use crate::widgets::widget::{Drawing, Located, Size, Widget};
const COLORS: [(f64, f64, f64); 12] = [
// yellow
(0.9882352941176471,0.9450980392156862,0.043137254901960784),
// orange
(1.0, 0.5843137254901961, 0.011764705882352941),
// white
(1.0, 1.0, 1.0),
// red
(0.9607843137254902, 0.00392156862745098, 0.00392156862745098),
// pink
(0.9725490196078431, 0.011764705882352941, 0.48627450980392156),
// purple
(0.6784313725490196, 0.00392156862745098, 0.4666666666666667),
// blue
(0.0, 0.00392156862745098, 0.8470588235294118),
// aqua
(0.0196078431372549, 0.615686274509804, 0.4666666666666667),
// goluboy
(0.03529411764705882, 0.7764705882352941, 0.792156862745098),
// deep orange
(0.8117647058823529, 0.2, 0.00784313725490196),
// light orange
(0.9450980392156862, 0.4980392156862745, 0.00784313725490196),
// peach
(0.9921568627450981, 0.7098039215686275, 0.16862745098039217),
];
#[derive(Debug)]
pub struct Chromachron;
impl Widget for Chromachron {
fn draw(&self, d: &Drawing, loc: Located) -> i32 {
// get the current time
let now = chrono::Local::now();
let hour = (now.hour() % 12) as usize;
let progress = now.minute() as f64 / 60.0;
let (lr, lg, lb) = if hour == 0 {
COLORS[11]
} else {
COLORS[hour - 1]
};
let (nr, ng, nb) = COLORS[hour % 12];
let sz = d.size.ht - (d.buffer as i32 * 2);
let offset = sz as f64 * progress;
let x = loc.target_x(d, sz);
d.ctx.set_source_rgb(nr, ng, nb);
d.ctx.rectangle(x, d.buffer, sz as f64 - offset, sz as f64);
d.ctx.fill();
d.ctx.set_source_rgb(lr, lg, lb);
d.ctx.rectangle(x + (sz as f64 - offset), d.buffer, offset, sz as f64);
d.ctx.fill();
sz
}
}