Skip to content

Commit

Permalink
prevent unnecessary redrawing of the time label
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjourney committed Dec 12, 2024
1 parent 1b665bf commit 42729f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace {
const int secs = (timeElapsedSecs) % 60;
const int mins = (timeElapsedSecs / 60) % 60;
const int hours = (timeElapsedSecs / 60) / 60;
return TimeSeparated {hours, mins, secs, hundredths};
return TimeSeparated {hours, mins, secs, hundredths, timeElapsedSecs};
}

void PlayPauseEventHandler(lv_obj_t* obj, lv_event_t event) {
Expand Down Expand Up @@ -145,11 +145,14 @@ void StopWatch::DisplayCleared() {

void StopWatch::RenderTime() {
TimeSeparated elapsedTime = ConvertTicksToTimeSegments(stopWatchController.GetElapsedTime());
SetHoursVisible(elapsedTime.hours != 0);
if (!hoursVisible) {
lv_label_set_text_fmt(time, "%02d:%02d", elapsedTime.mins, elapsedTime.secs);
} else {
lv_label_set_text_fmt(time, "%02d:%02d:%02d", elapsedTime.hours, elapsedTime.mins, elapsedTime.secs);
renderedSeconds = elapsedTime.epochSecs;
if (renderedSeconds.IsUpdated()) {
SetHoursVisible(elapsedTime.hours != 0);
if (!hoursVisible) {
lv_label_set_text_fmt(time, "%02d:%02d", elapsedTime.mins, elapsedTime.secs);
} else {
lv_label_set_text_fmt(time, "%02d:%02d:%02d", elapsedTime.hours, elapsedTime.mins, elapsedTime.secs);
}
}
lv_label_set_text_fmt(msecTime, "%02d", elapsedTime.hundredths);
}
Expand Down
3 changes: 3 additions & 0 deletions src/displayapp/screens/StopWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
#include "Symbols.h"
#include "utility/DirtyValue.h"

namespace Pinetime::Applications {
namespace Screens {
Expand All @@ -16,6 +17,7 @@ namespace Pinetime::Applications {
int mins;
int secs;
int hundredths;
int epochSecs;
};

class StopWatch : public Screen {
Expand Down Expand Up @@ -47,6 +49,7 @@ namespace Pinetime::Applications {
int displayedLaps = 3;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t* lapText;
Utility::DirtyValue<TickType_t> renderedSeconds;
bool hoursVisible = false;

lv_task_t* taskRefresh;
Expand Down

0 comments on commit 42729f8

Please sign in to comment.