Skip to content

Commit

Permalink
feat(upower): icon size option
Browse files Browse the repository at this point in the history
Adds missing `icon_size` config option to upower module.
  • Loading branch information
JakeStanger committed May 26, 2023
1 parent e6a70f7 commit c3e9654
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions docs/modules/Upower.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Displays system power information such as the battery percentage, and estimated

> Type: `upower`
| Name | Type | Default | Description |
|----------|----------|-----------------|---------------------------------------------------|
| `format` | `string` | `{percentage}%` | Format string to use for the widget button label. |
| Name | Type | Default | Description |
|-------------|-----------|-----------------|---------------------------------------------------|
| `format` | `string` | `{percentage}%` | Format string to use for the widget button label. |
| `icon_size` | `integer` | `24` | Size to render icon at. |

<details>
<summary>JSON</summary>
Expand Down
9 changes: 8 additions & 1 deletion src/modules/upower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct UpowerModule {
#[serde(default = "default_format")]
format: String,

#[serde(default = "default_icon_size")]
icon_size: i32,

#[serde(flatten)]
pub common: Option<CommonConfig>,
}
Expand All @@ -32,6 +35,10 @@ fn default_format() -> String {
String::from("{percentage}%")
}

const fn default_icon_size() -> i32 {
24
}

#[derive(Clone, Debug)]
pub struct UpowerProperties {
percentage: f64,
Expand Down Expand Up @@ -180,7 +187,7 @@ impl Module<gtk::Button> for UpowerModule {
.attach(None, move |properties: UpowerProperties| {
let format = format.replace("{percentage}", &properties.percentage.to_string());
let icon_name = String::from("icon:") + &properties.icon_name;
ImageProvider::parse(&icon_name, &icon_theme, 24)
ImageProvider::parse(&icon_name, &icon_theme, self.icon_size)
.map(|provider| provider.load_into_image(icon.clone()));
label.set_markup(format.as_ref());
Continue(true)
Expand Down

0 comments on commit c3e9654

Please sign in to comment.