Add a basic framework for applying styles

This commit is contained in:
Emi Simpson 2021-12-30 17:58:56 -05:00
parent 558b32ae28
commit a62702acdc
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
3 changed files with 37 additions and 1 deletions

View File

@ -2,12 +2,17 @@ use iced::Container;
use iced::Row;
use iced::Element;
use iced::Sandbox;
use iced::Length;
mod lyrics;
mod styles;
use styles::Theme;
#[derive(Clone, Debug)]
pub struct DelyriumApp {
lyrics_component: lyrics::Lyrics,
theme: Theme,
}
#[derive(Clone, Debug)]
@ -24,6 +29,7 @@ impl Sandbox for DelyriumApp {
fn new() -> Self {
DelyriumApp {
lyrics_component: lyrics::Lyrics::new(),
theme: Theme::default(),
}
}
@ -40,6 +46,8 @@ impl Sandbox for DelyriumApp {
Row::new()
.push(self.lyrics_component.view())
)
.style(self.theme)
.height(Length::Fill)
.into()
}
}

28
src/app/styles.rs Normal file
View File

@ -0,0 +1,28 @@
use iced::Background;
use iced::Color;
use iced::widget::container;
#[derive(Copy, Clone, Debug)]
pub struct Theme {
pub base_color: Color,
pub text_color: Color,
}
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()
}
}
}

View File

@ -5,5 +5,5 @@ mod palette;
mod app;
fn main() {
app::DelyriumApp::run(Settings::default());
app::DelyriumApp::run(Settings::default()).unwrap();
}