Eerste opzet
This commit is contained in:
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::rc::Rc;
|
||||
use slint::{Color, VecModel};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
fn hsl_to_rgb(hue: f32, sat: f32, light: f32) -> (u8, u8, u8) {
|
||||
let c = (1.0 - (2.0 * light - 1.0).abs()) * sat;
|
||||
let x = c * (1.0 - ((hue / 60.0) % 2.0 - 1.0).abs());
|
||||
let m = light - c / 2.0;
|
||||
|
||||
let (r, g, b) = match (hue as u32) % 360 {
|
||||
h if h < 60 => (c, x, 0.0),
|
||||
h if h < 120 => (x, c, 0.0),
|
||||
h if h < 180 => (0.0, c, x),
|
||||
h if h < 240 => (0.0, x, c),
|
||||
h if h < 300 => (x, 0.0, c),
|
||||
_ => (c, 0.0, x),
|
||||
};
|
||||
|
||||
(
|
||||
((r + m) * 255.0) as u8,
|
||||
((g + m) * 255.0) as u8,
|
||||
((b + m) * 255.0) as u8,
|
||||
)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), slint::PlatformError> {
|
||||
let demo = DemoWindow::new()?;
|
||||
|
||||
let colors: Vec<slint::Brush> = (0..38)
|
||||
.map(|i| {
|
||||
let hue = (i as f32 / 38.0) * 360.0;
|
||||
let (r, g, b) = hsl_to_rgb(hue, 0.85, 0.55);
|
||||
Color::from_rgb_u8(r, g, b).into()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let model: Rc<VecModel<slint::Brush>> = Rc::new(VecModel::from(colors));
|
||||
demo.set_bar_colors(model.into());
|
||||
demo.set_window_title("DEMO Slint".into());
|
||||
|
||||
demo.run()
|
||||
}
|
||||
Reference in New Issue
Block a user