Skip to content

Commit 2cb1920

Browse files
committed
Dynamically remove minutes from timer
Removes the minute counter from the timer when under a minute to allow displaying the remaining second count with more icons.
1 parent 1644837 commit 2cb1920

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/displayapp/widgets/StatusIcons.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void StatusIcons::Update() {
7878

7979
if (timer.IsRunning()) {
8080
uint8_t activeIconCounter = 0;
81+
uint8_t maxIcons = 0;
8182
lv_obj_t* child = lv_obj_get_child(container, NULL);
8283

8384
while (child != NULL) {
@@ -100,17 +101,21 @@ void StatusIcons::Update() {
100101
activeIconCounter--;
101102
}
102103

103-
// more than 2 icons (plus the batteryIcon) make the timerContainer collide
104-
// with other text, so replace it with a timer icon
105-
if (activeIconCounter > 2) {
104+
std::chrono::seconds secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
105+
uint8_t timerMinutes = (secondsRemaining.count() % 3600) / 60;
106+
uint8_t timerSeconds = secondsRemaining.count() % 60;
107+
if (timerMinutes > 0) {
108+
maxIcons = 2;
109+
lv_label_set_text_fmt(timeRemaining, "%02d:%02d", timerMinutes, timerSeconds);
110+
} else {
111+
maxIcons = 3;
112+
lv_label_set_text_fmt(timeRemaining, ":%02d", timerSeconds);
113+
}
114+
115+
if (activeIconCounter > maxIcons) {
106116
lv_obj_set_hidden(timerContainer, true);
107117
lv_obj_set_hidden(soloTimerIcon, false);
108118
} else {
109-
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
110-
uint8_t minutes = secondsRemaining.count() / 60;
111-
uint8_t seconds = secondsRemaining.count() % 60;
112-
lv_label_set_text_fmt(timeRemaining, "%02d:%02d", minutes, seconds);
113-
114119
lv_obj_set_hidden(soloTimerIcon, true);
115120
lv_obj_set_hidden(timerContainer, false);
116121
}

0 commit comments

Comments
 (0)