Skip to content

Commit

Permalink
Merge pull request #139 from LordMZTE/color-config
Browse files Browse the repository at this point in the history
feat: make color configuration more flexible
  • Loading branch information
gabm authored Dec 20, 2024
2 parents 95fec55 + 3d96855 commit 33d94a9
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 167 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,28 @@ disable-notifications = false
family = "Roboto"
style = "Bold"

# custom colours for the colour palette
# Custom colours for the colour palette
[color-palette]
first= "#00ffff"
second= "#a52a2a"
third= "#dc143c"
fourth= "#ff1493"
fifth= "#ffd700"
custom= "#008000"
# These will be shown in the toolbar for quick selection
palette = [
"#00ffff",
"#a52a2a",
"#dc143c",
"#ff1493",
"#ffd700",
"#008000",
]

# These will be available in the color picker as presets
# Leave empty to use GTK's default
custom = [
"#00ffff",
"#a52a2a",
"#dc143c",
"#ff1493",
"#ffd700",
"#008000",
]
```

### Command Line
Expand Down
52 changes: 9 additions & 43 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 19 additions & 53 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,57 +72,25 @@ impl FontConfiguration {
}

pub struct ColorPalette {
first: Color,
second: Color,
third: Color,
fourth: Color,
fifth: Color,
custom: Color,
palette: Vec<Color>,
custom: Vec<Color>,
}

impl ColorPalette {
pub fn first(&self) -> Color {
self.first
pub fn palette(&self) -> &[Color] {
&self.palette
}

pub fn second(&self) -> Color {
self.second
}

pub fn third(&self) -> Color {
self.third
}

pub fn fourth(&self) -> Color {
self.fourth
}

pub fn fifth(&self) -> Color {
self.fifth
}

pub fn custom(&self) -> Color {
self.custom
pub fn custom(&self) -> &[Color] {
&self.custom
}

fn merge(&mut self, file_palette: ColorPaletteFile) {
if let Some(v) = file_palette.first {
self.first = v.into();
}
if let Some(v) = file_palette.second {
self.second = v.into();
}
if let Some(v) = file_palette.third {
self.third = v.into();
}
if let Some(v) = file_palette.fourth {
self.fourth = v.into();
}
if let Some(v) = file_palette.fifth {
self.fifth = v.into();
if let Some(v) = file_palette.palette {
self.palette = v.into_iter().map(Color::from).collect();
}
if let Some(v) = file_palette.custom {
self.custom = v.into();
self.custom = v.into_iter().map(Color::from).collect();
}
}
}
Expand Down Expand Up @@ -326,12 +294,14 @@ impl Default for Configuration {
impl Default for ColorPalette {
fn default() -> Self {
Self {
first: Color::orange(),
second: Color::red(),
third: Color::green(),
fourth: Color::blue(),
fifth: Color::cove(),
custom: Color::pink(),
palette: vec![
Color::orange(),
Color::red(),
Color::green(),
Color::blue(),
Color::cove(),
],
custom: vec![],
}
}
}
Expand Down Expand Up @@ -370,12 +340,8 @@ struct ConfigurationFileGeneral {
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
struct ColorPaletteFile {
first: Option<HexColor>,
second: Option<HexColor>,
third: Option<HexColor>,
fourth: Option<HexColor>,
fifth: Option<HexColor>,
custom: Option<HexColor>,
palette: Option<Vec<HexColor>>,
custom: Option<Vec<HexColor>>,
}

impl ConfigurationFile {
Expand Down
8 changes: 7 additions & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub enum Size {

impl Default for Color {
fn default() -> Self {
APP_CONFIG.read().color_palette().first()
APP_CONFIG
.read()
.color_palette()
.palette()
.first()
.copied()
.unwrap_or(Color::red())
}
}

Expand Down
Loading

0 comments on commit 33d94a9

Please sign in to comment.