Skip to content

Commit

Permalink
Fix fltk frontend colors
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed Jun 20, 2024
1 parent 103e106 commit 09ed33f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 55 deletions.
7 changes: 0 additions & 7 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ frontend:
# ## Google has a color picker if you search for, well, "color picker".
# colors:
# background: 0x202020
# accent: 0xbf6c0d
# text: 0xffffff
#
# ## Alternative representation which is more customizable.
# ## Chose *either* block, not both.
# # colors:
# background: 0x202020
# query_text: 0xffffff
# query_cursor: 0xbf6c0d
# query_highlight: 0xbf6c0d
Expand Down
50 changes: 2 additions & 48 deletions gravel-frontend-fltk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ pub struct Layout {
#[derive(Deserialize, Debug)]
pub struct Config {
pub layout: Layout,
#[serde(deserialize_with = "deserialize::colors")]
pub colors: DetailedColors,
pub colors: Colors,
pub behaviour: Behaviour,
}

#[derive(Deserialize, Debug)]
pub struct DetailedColors {
pub struct Colors {
#[serde(deserialize_with = "deserialize::color")]
pub background: Color,
#[serde(deserialize_with = "deserialize::color")]
Expand All @@ -86,51 +85,6 @@ pub mod deserialize {
u32::deserialize(de).map(Color::from_hex)
}

pub fn colors<'de, D: Deserializer<'de>>(de: D) -> Result<super::DetailedColors, D::Error> {
ColorVariants::deserialize(de).map(Into::into)
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum ColorVariants {
SimpleColors(SimpleColors),
DetailedColors(super::DetailedColors),
}

#[derive(Deserialize, Debug)]
pub struct SimpleColors {
#[serde(deserialize_with = "color")]
pub background: Color,
#[serde(deserialize_with = "color")]
pub accent: Color,
#[serde(deserialize_with = "color")]
pub text: Color,
}

impl From<ColorVariants> for super::DetailedColors {
fn from(val: ColorVariants) -> Self {
match val {
ColorVariants::SimpleColors(colors) => colors.into(),
ColorVariants::DetailedColors(colors) => colors,
}
}
}

impl From<SimpleColors> for super::DetailedColors {
fn from(val: SimpleColors) -> Self {
super::DetailedColors {
background: val.background,
query_text: val.text,
query_cursor: val.accent,
query_highlight: val.accent,
hit_title: val.text,
hit_subtitle: val.text,
hit_highlight: val.accent,
scrollbar: val.accent,
}
}
}

#[derive(Deserialize, Debug)]
pub struct Layout {
pub scale: f32,
Expand Down

0 comments on commit 09ed33f

Please sign in to comment.