Skip to content

Commit

Permalink
length of lap list adapting to available space
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjourney committed Nov 30, 2024
1 parent 311eaf0 commit 0c402c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/stopwatch/StopWatchController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/stopwatch/StopWatchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<LapInfo> 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) {
Expand All @@ -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();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/StopWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0c402c7

Please sign in to comment.