diff --git a/src/components/stopwatch/StopWatchController.cpp b/src/components/stopwatch/StopWatchController.cpp index 64261055a0..4979ee6844 100644 --- a/src/components/stopwatch/StopWatchController.cpp +++ b/src/components/stopwatch/StopWatchController.cpp @@ -33,9 +33,9 @@ void StopWatchController::Clear() { void StopWatchController::AddLapToHistory() { TickType_t lapEnd = GetElapsedTime(); + history--; history[0].timeSinceStart = lapEnd; history[0].number = ++maxLapNumber % lapNumberBoundary; - history--; } int StopWatchController::GetMaxLapNumber() { diff --git a/src/components/stopwatch/StopWatchController.h b/src/components/stopwatch/StopWatchController.h index 6aaec2b21d..210cbeaac0 100644 --- a/src/components/stopwatch/StopWatchController.h +++ b/src/components/stopwatch/StopWatchController.h @@ -56,7 +56,7 @@ namespace Pinetime { TickType_t timeElapsedPreviously; // Maximum number of stored laps - static constexpr int histSize = 2; + static constexpr int histSize = 4; // Value at which lap numbers wrap around to zero static constexpr int lapNumberBoundary = 1000; // Lap storage diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 5d77fdcc76..ef5ee6f537 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -57,7 +57,7 @@ StopWatch::StopWatch(System::SystemTask& systemTask, StopWatchController& stopWa lapText = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(lapText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); - lv_label_set_text_static(lapText, "\n"); + lv_label_set_text_static(lapText, ""); lv_label_set_long_mode(lapText, LV_LABEL_LONG_BREAK); lv_label_set_align(lapText, LV_LABEL_ALIGN_CENTER); lv_obj_set_width(lapText, LV_HOR_RES_MAX); @@ -170,24 +170,23 @@ void StopWatch::RenderPause() { void StopWatch::RenderLaps() { lv_label_set_text(lapText, ""); - for (int i = 0; i < displayedLaps; i++) { + for (int i = displayedLaps - 1; i >= 0; i--) { std::optional lap = stopWatchController.GetLapFromHistory(i); if (lap) { TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart); char buffer[19]; if (laptime.hours == 0) { - snprintf(buffer, sizeof(buffer), "#%-3d %2d:%02d.%02d\n", + snprintf(buffer, sizeof(buffer), "\n#%-3d %2d:%02d.%02d", lap->number, laptime.mins, laptime.secs, laptime.hundredths); } else { - snprintf(buffer, sizeof(buffer), "#%-3d %3d:%02d:%02d.%02d\n", + snprintf(buffer, sizeof(buffer), "\n#%-3d %3d:%02d:%02d.%02d", lap->number, laptime.hours, laptime.mins, laptime.secs, laptime.hundredths); } lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer); - } else { - lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n"); } } + lv_obj_realign(lapText); } void StopWatch::SetHoursVisible(bool visible) { @@ -196,7 +195,11 @@ void StopWatch::SetHoursVisible(bool visible) { lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font); lv_obj_set_height(time, font->line_height); lv_obj_realign(msecTime); + displayedLaps = visible ? 4 : 3; hoursVisible = visible; + if (stopWatchController.GetLapFromHistory(0)) { + RenderLaps(); + } } } diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index f797a49678..0e27ab00d3 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -44,7 +44,7 @@ namespace Pinetime::Applications { Pinetime::System::WakeLock wakeLock; Controllers::StopWatchController& stopWatchController; TickType_t blinkTime = 0; - static constexpr int displayedLaps = 2; + int displayedLaps = 3; lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap; lv_obj_t* lapText; bool hoursVisible = false;