Better tray ToolTip
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use ksni::{Tray, MenuItem, menu::{StandardItem}};
|
use ksni::{Tray, MenuItem, menu::{StandardItem}, ToolTip};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BatteryTray {
|
pub struct BatteryTray {
|
||||||
@@ -14,7 +14,7 @@ impl BatteryTray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh(&mut self, battery_level: u8, charging: bool) {
|
pub fn update(&mut self, battery_level: u8, charging: bool) {
|
||||||
self.battery_level = battery_level;
|
self.battery_level = battery_level;
|
||||||
self.charging = charging;
|
self.charging = charging;
|
||||||
}
|
}
|
||||||
@@ -24,13 +24,6 @@ impl Tray for BatteryTray {
|
|||||||
fn icon_name(&self) -> String {
|
fn icon_name(&self) -> String {
|
||||||
"headset".into()
|
"headset".into()
|
||||||
}
|
}
|
||||||
fn title(&self) -> String {
|
|
||||||
if self.charging {
|
|
||||||
format!("Battery level: {}%\nCharging", self.battery_level).to_string()
|
|
||||||
} else {
|
|
||||||
format!("Battery level: {}%\nNot charging", self.battery_level).to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn menu(&self) -> Vec<MenuItem<Self>> {
|
fn menu(&self) -> Vec<MenuItem<Self>> {
|
||||||
vec![
|
vec![
|
||||||
StandardItem {
|
StandardItem {
|
||||||
@@ -42,4 +35,17 @@ impl Tray for BatteryTray {
|
|||||||
.into(),
|
.into(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
fn tool_tip(&self) -> ToolTip {
|
||||||
|
let description = if self.charging {
|
||||||
|
format!("Battery level: {}%\nCharging", self.battery_level)
|
||||||
|
} else {
|
||||||
|
format!("Battery level: {}%\nNot charging", self.battery_level)
|
||||||
|
};
|
||||||
|
ToolTip {
|
||||||
|
title: "HyperX Cloud II".to_string(),
|
||||||
|
description: description,
|
||||||
|
icon_name: "".into(),
|
||||||
|
icon_pixmap: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
handle.update(|tray: &mut BatteryTray| {
|
handle.update(|tray: &mut BatteryTray| {
|
||||||
tray.refresh(battery_level, charging);
|
tray.update(battery_level, charging);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user