deLyrium/src/styles.rs

79 lines
1.5 KiB
Rust

use image::Rgb;
use crate::palette::Palette;
use iced::Background;
use iced::Color;
use iced::widget::container;
use iced::widget::text_input;
#[derive(Copy, Clone, Debug)]
pub struct Theme {
pub base_color: Color,
pub text_color: Color,
}
impl Theme {
pub fn from_palette(palette: Palette) -> Self {
Theme {
base_color: img_color_to_iced(palette.dominant_color()),
text_color: Color::WHITE,
}
}
}
impl Default for Theme {
fn default() -> Self {
Theme {
base_color: Color {r: 236. / 255., g: 63. / 255., b: 53. / 255., a: 1.},
text_color: Color {r: 1., g: 1., b: 1., a: 1.},
}
}
}
impl container::StyleSheet for Theme {
fn style(&self) -> container::Style {
container::Style {
text_color: Some(self.text_color),
background: Some(Background::Color(self.base_color)),
..Default::default()
}
}
}
impl text_input::StyleSheet for Theme {
fn active(&self) -> text_input::Style {
text_input::Style {
background: Background::Color(self.base_color),
border_radius: 0.,
border_width: 0.,
..Default::default()
}
}
fn focused(&self) -> text_input::Style {
self.active()
}
fn placeholder_color(&self) -> Color {
let mut color = self.text_color;
color.a = 0.5;
color
}
fn value_color(&self) -> Color {
self.text_color
}
fn selection_color(&self) -> Color {
self.text_color
}
}
fn img_color_to_iced(color: &Rgb<u8>) -> Color {
Color {
r: color[0] as f32 / 255.,
g: color[1] as f32 / 255.,
b: color[2] as f32 / 255.,
a: 1.
}
}