1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

Merge pull request #160 from JakeStanger/feat/upower-icon-size

feat(upower): icon size option
This commit is contained in:
Jake Stanger 2023-06-18 17:01:57 +01:00 committed by GitHub
commit 5be0750792
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -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>

View file

@ -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>,
}
@ -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,
@ -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)