Fixed an issue where the battery text was not updated correctly when changing its menu option

This commit is contained in:
Leon Styhre 2025-02-26 12:59:18 +01:00
parent 819b79c8c1
commit 3d56fd68d1
2 changed files with 22 additions and 12 deletions

View file

@ -21,6 +21,8 @@ SystemStatusComponent::SystemStatusComponent()
, mHasCellular {false} , mHasCellular {false}
, mHasBattery {false} , mHasBattery {false}
, mBatteryCharging {false} , mBatteryCharging {false}
, mBatteryText {Settings::getInstance()->getBool("SystemStatusBattery") &&
Settings::getInstance()->getBool("SystemStatusBatteryPercentage")}
, mBatteryCapacity {100} , mBatteryCapacity {100}
, mEntries {sAllowedEntries} , mEntries {sAllowedEntries}
, mColorShift {0xFFFFFFFF} , mColorShift {0xFFFFFFFF}
@ -64,13 +66,13 @@ void SystemStatusComponent::updateGrid()
if (mDisplayEntries.empty()) if (mDisplayEntries.empty())
return; return;
const bool batteryText {Settings::getInstance()->getBool("SystemStatusBattery") && mBatteryText = Settings::getInstance()->getBool("SystemStatusBattery") &&
Settings::getInstance()->getBool("SystemStatusBatteryPercentage")}; Settings::getInstance()->getBool("SystemStatusBatteryPercentage");
int numEntries {static_cast<int>(mDisplayEntries.size())}; int numEntries {static_cast<int>(mDisplayEntries.size())};
if (mEntrySpacing != 0.0f) if (mEntrySpacing != 0.0f)
numEntries += numEntries - 1; numEntries += numEntries - 1;
if (mHasBattery && batteryText) if (mHasBattery && mBatteryText)
++numEntries; ++numEntries;
mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {numEntries, 1}); mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {numEntries, 1});
@ -118,7 +120,7 @@ void SystemStatusComponent::updateGrid()
} }
} }
if (mHasBattery && batteryText) { if (mHasBattery && mBatteryText) {
// We set the initial value to "100%" to calculate the cell size based on this, as this // We set the initial value to "100%" to calculate the cell size based on this, as this
// will be the longest text that will ever be displayed for the battery capacity. // will be the longest text that will ever be displayed for the battery capacity.
mBatteryPercentage = std::make_shared<TextComponent>( mBatteryPercentage = std::make_shared<TextComponent>(
@ -134,7 +136,7 @@ void SystemStatusComponent::updateGrid()
for (int i {0}; i < static_cast<int>(mGrid->getChildCount()); ++i) { for (int i {0}; i < static_cast<int>(mGrid->getChildCount()); ++i) {
mGrid->setColWidthPerc(i, mGrid->getChild(i)->getSize().x / width); mGrid->setColWidthPerc(i, mGrid->getChild(i)->getSize().x / width);
if (mHasBattery && batteryText && i == static_cast<int>(mGrid->getChildCount()) - 2) if (mHasBattery && mBatteryText && i == static_cast<int>(mGrid->getChildCount()) - 2)
continue; continue;
if (mEntrySpacing != 0.0f && i != static_cast<int>(mGrid->getChildCount()) - 1) { if (mEntrySpacing != 0.0f && i != static_cast<int>(mGrid->getChildCount()) - 1) {
@ -335,13 +337,20 @@ void SystemStatusComponent::update(int deltaTime)
statusChanged = true; statusChanged = true;
batteryStatusChanged = true; batteryStatusChanged = true;
} }
if (mHasBattery && mBatteryCharging != status.batteryCharging) { if (mHasBattery) {
mBatteryCharging = status.batteryCharging; if (mBatteryCharging != status.batteryCharging) {
batteryStatusChanged = true; mBatteryCharging = status.batteryCharging;
} batteryStatusChanged = true;
if (mHasBattery && mBatteryCapacity != status.batteryCapacity) { }
mBatteryCapacity = status.batteryCapacity; if (mBatteryCapacity != status.batteryCapacity) {
batteryStatusChanged = true; mBatteryCapacity = status.batteryCapacity;
batteryStatusChanged = true;
}
if ((Settings::getInstance()->getBool("SystemStatusBattery") &&
Settings::getInstance()->getBool("SystemStatusBatteryPercentage")) !=
mBatteryText) {
statusChanged = true;
}
} }
if (statusChanged) { if (statusChanged) {

View file

@ -43,6 +43,7 @@ private:
bool mHasCellular; bool mHasCellular;
bool mHasBattery; bool mHasBattery;
bool mBatteryCharging; bool mBatteryCharging;
bool mBatteryText;
int mBatteryCapacity; int mBatteryCapacity;
std::vector<std::string> mEntries; std::vector<std::string> mEntries;