Skip to content

Commit 6431b40

Browse files
codingjourneyJF002
authored andcommitted
length of lap list adapting to available space
1 parent 5f85072 commit 6431b40

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/components/stopwatch/StopWatchController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void StopWatchController::Clear() {
3333

3434
void StopWatchController::AddLapToHistory() {
3535
TickType_t lapEnd = GetElapsedTime();
36+
history--;
3637
history[0].timeSinceStart = lapEnd;
3738
history[0].number = ++maxLapNumber % lapNumberBoundary;
38-
history--;
3939
}
4040

4141
int StopWatchController::GetMaxLapNumber() {

src/components/stopwatch/StopWatchController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace Pinetime {
5656
TickType_t timeElapsedPreviously;
5757

5858
// Maximum number of stored laps
59-
static constexpr int histSize = 2;
59+
static constexpr int histSize = 4;
6060
// Value at which lap numbers wrap around to zero
6161
static constexpr int lapNumberBoundary = 1000;
6262
// Lap storage

src/displayapp/screens/StopWatch.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ StopWatch::StopWatch(System::SystemTask& systemTask, StopWatchController& stopWa
5757

5858
lapText = lv_label_create(lv_scr_act(), nullptr);
5959
lv_obj_set_style_local_text_color(lapText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
60-
lv_label_set_text_static(lapText, "\n");
60+
lv_label_set_text_static(lapText, "");
6161
lv_label_set_long_mode(lapText, LV_LABEL_LONG_BREAK);
6262
lv_label_set_align(lapText, LV_LABEL_ALIGN_CENTER);
6363
lv_obj_set_width(lapText, LV_HOR_RES_MAX);
@@ -170,24 +170,23 @@ void StopWatch::RenderPause() {
170170

171171
void StopWatch::RenderLaps() {
172172
lv_label_set_text(lapText, "");
173-
for (int i = 0; i < displayedLaps; i++) {
173+
for (int i = displayedLaps - 1; i >= 0; i--) {
174174
std::optional<LapInfo> lap = stopWatchController.GetLapFromHistory(i);
175175

176176
if (lap) {
177177
TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart);
178178
char buffer[19];
179179
if (laptime.hours == 0) {
180-
snprintf(buffer, sizeof(buffer), "#%-3d %2d:%02d.%02d\n",
180+
snprintf(buffer, sizeof(buffer), "\n#%-3d %2d:%02d.%02d",
181181
lap->number, laptime.mins, laptime.secs, laptime.hundredths);
182182
} else {
183-
snprintf(buffer, sizeof(buffer), "#%-3d %3d:%02d:%02d.%02d\n",
183+
snprintf(buffer, sizeof(buffer), "\n#%-3d %3d:%02d:%02d.%02d",
184184
lap->number, laptime.hours, laptime.mins, laptime.secs, laptime.hundredths);
185185
}
186186
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
187-
} else {
188-
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n");
189187
}
190188
}
189+
lv_obj_realign(lapText);
191190
}
192191

193192
void StopWatch::SetHoursVisible(bool visible) {
@@ -196,7 +195,11 @@ void StopWatch::SetHoursVisible(bool visible) {
196195
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font);
197196
lv_obj_set_height(time, font->line_height);
198197
lv_obj_realign(msecTime);
198+
displayedLaps = visible ? 4 : 3;
199199
hoursVisible = visible;
200+
if (stopWatchController.GetLapFromHistory(0)) {
201+
RenderLaps();
202+
}
200203
}
201204
}
202205

src/displayapp/screens/StopWatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace Pinetime::Applications {
4444
Pinetime::System::WakeLock wakeLock;
4545
Controllers::StopWatchController& stopWatchController;
4646
TickType_t blinkTime = 0;
47-
static constexpr int displayedLaps = 2;
47+
int displayedLaps = 3;
4848
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
4949
lv_obj_t* lapText;
5050
bool hoursVisible = false;

0 commit comments

Comments
 (0)