Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move rounding into border table and optimize border drawing with encapsulation #9

Merged
merged 7 commits into from
Jul 15, 2024
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ height = 150

[display]
image_size = 64

rounding = 10
padding = 8

timeout = 2000
Expand All @@ -58,12 +56,13 @@ foreground = "#1E1E2E"

[display.border]
size = 4
radius = 10
color = "#000"

[[app]]
name = "Telegram Desktop"
[app.display]
rounding = 8
border = { radius = 8 }
markup = true

[app.display.body]
Expand Down
21 changes: 11 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ impl From<String> for Anchor {
pub struct DisplayConfig {
image_size: Option<u16>,

rounding: Option<u8>,
padding: Option<u8>,

border: Option<Border>,
Expand All @@ -243,10 +242,6 @@ impl DisplayConfig {
self.image_size.unwrap()
}

pub fn rounding(&self) -> u8 {
self.rounding.unwrap()
}

pub fn padding(&self) -> u8 {
self.padding.unwrap()
}
Expand Down Expand Up @@ -280,10 +275,6 @@ impl DisplayConfig {
self.image_size = Some(64);
}

if self.rounding.is_none() {
self.rounding = Some(0);
}

if self.padding.is_none() {
self.padding = Some(0);
}
Expand Down Expand Up @@ -435,6 +426,7 @@ impl From<String> for Color {
#[derive(Debug, Deserialize, Default, Clone)]
pub struct Border {
size: Option<u8>,
radius: Option<u8>,
color: Option<Color>,
}

Expand All @@ -443,6 +435,10 @@ impl Border {
self.size.unwrap()
}

pub fn radius(&self) -> u8 {
self.radius.unwrap()
}

pub fn color(&self) -> &Color {
self.color.as_ref().unwrap()
}
Expand All @@ -452,6 +448,10 @@ impl Border {
self.size = Some(0);
}

if self.radius.is_none() {
self.radius = Some(0);
}

if self.color.is_none() {
self.color = Some(Default::default());
}
Expand Down Expand Up @@ -528,12 +528,13 @@ impl AppConfig {
if let Some(display) = self.display.as_mut() {
display.image_size = display.image_size.or(other.image_size);

display.rounding = display.rounding.or(other.rounding);
display.padding = display.padding.or(other.padding);

if let Some(border) = display.border.as_mut() {
let other_border = other.border(); // The other type shall have border

border.size = border.size.or(other_border.size);
border.radius = border.radius.or(other_border.radius);
border.color = border.color.clone().or(other_border.color.clone());
} else {
display.border = other.border.clone();
Expand Down
Loading