Only set label text if string doesn't only contain spaces

This commit is contained in:
Erik Reider 2022-03-20 00:36:53 +01:00
parent 7b071567ea
commit e06316c80b
1 changed files with 25 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <cstring>
#include <string> #include <string>
#include "gtkmm/icontheme.h" #include "gtkmm/icontheme.h"
@ -312,9 +313,30 @@ auto UPower::update() -> void {
} }
// Label format // Label format
label_.set_markup(fmt::format(showAltText ? format_alt : format, std::string time_format = "";
switch (state) {
case UP_DEVICE_STATE_CHARGING:
case UP_DEVICE_STATE_PENDING_CHARGE:
time_format = timeToString(time_full);
break;
case UP_DEVICE_STATE_DISCHARGING:
case UP_DEVICE_STATE_PENDING_DISCHARGE:
time_format = timeToString(time_empty);
break;
default:
break;
}
std::string label_format = fmt::format(showAltText ? format_alt : format,
fmt::arg("percentage", percentString), fmt::arg("percentage", percentString),
fmt::arg("time", time_format))); fmt::arg("time", time_format));
// Only set the label text if it doesn't only contain spaces
bool onlySpaces = true;
for (auto& character : label_format) {
if (character == ' ') continue;
onlySpaces = false;
break;
}
label_.set_markup(onlySpaces ? "" : label_format);
// Set icon // Set icon
if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) { if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) {