Skip to content

Commit a6122a2

Browse files
committed
improved layout, improved re-alignment of time fields
1 parent a715ff3 commit a6122a2

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

src/displayapp/screens/StopWatch.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ StopWatch::StopWatch(System::SystemTask& systemTask, StopWatchController& stopWa
6363
lv_obj_set_width(lapText, LV_HOR_RES_MAX);
6464
lv_obj_align(lapText, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -btnHeight);
6565

66-
msecTime = lv_label_create(lv_scr_act(), nullptr);
67-
lv_label_set_text_static(msecTime, "00");
68-
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DISABLED, Colors::lightGray);
69-
lv_obj_align(msecTime, lapText, LV_ALIGN_OUT_TOP_MID, 0, 0);
70-
7166
time = lv_label_create(lv_scr_act(), nullptr);
67+
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DISABLED, Colors::lightGray);
7268
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
7369
lv_label_set_text_static(time, "00:00");
74-
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DISABLED, Colors::lightGray);
75-
lv_obj_align(time, msecTime, LV_ALIGN_OUT_TOP_MID, 0, 0);
70+
lv_label_set_long_mode(time, LV_LABEL_LONG_CROP);
71+
lv_label_set_align(time, LV_LABEL_ALIGN_CENTER);
72+
lv_obj_set_width(time, LV_HOR_RES_MAX);
73+
lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
74+
75+
msecTime = lv_label_create(lv_scr_act(), nullptr);
76+
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DISABLED, Colors::lightGray);
77+
lv_label_set_text_static(msecTime, "00");
78+
lv_obj_align(msecTime, time, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
7679

7780
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
7881

@@ -131,11 +134,7 @@ void StopWatch::DisplayCleared() {
131134
lv_label_set_text_static(time, "00:00");
132135
lv_label_set_text_static(msecTime, "00");
133136

134-
if (isHoursLabelUpdated) {
135-
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
136-
lv_obj_realign(time);
137-
isHoursLabelUpdated = false;
138-
}
137+
SetHoursVisible(false);
139138

140139
lv_label_set_text_static(lapText, "");
141140
lv_label_set_text_static(txtPlayPause, Symbols::play);
@@ -145,18 +144,14 @@ void StopWatch::DisplayCleared() {
145144
}
146145

147146
void StopWatch::RenderTime() {
148-
TimeSeparated currentTimeSeparated = ConvertTicksToTimeSegments(stopWatchController.GetElapsedTime());
149-
if (currentTimeSeparated.hours == 0) {
150-
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
147+
TimeSeparated elapsedTime = ConvertTicksToTimeSegments(stopWatchController.GetElapsedTime());
148+
SetHoursVisible(elapsedTime.hours != 0);
149+
if (!hoursVisible) {
150+
lv_label_set_text_fmt(time, "%02d:%02d", elapsedTime.mins, elapsedTime.secs);
151151
} else {
152-
lv_label_set_text_fmt(time, "%02d:%02d:%02d", currentTimeSeparated.hours, currentTimeSeparated.mins, currentTimeSeparated.secs);
153-
if (!isHoursLabelUpdated) {
154-
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
155-
lv_obj_realign(time);
156-
isHoursLabelUpdated = true;
157-
}
152+
lv_label_set_text_fmt(time, "%02d:%02d:%02d", elapsedTime.hours, elapsedTime.mins, elapsedTime.secs);
158153
}
159-
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
154+
lv_label_set_text_fmt(msecTime, "%02d", elapsedTime.hundredths);
160155
}
161156

162157
void StopWatch::RenderPause() {
@@ -195,6 +190,16 @@ void StopWatch::RenderLaps() {
195190
}
196191
}
197192

193+
void StopWatch::SetHoursVisible(bool visible) {
194+
if (hoursVisible != visible) {
195+
lv_font_t *font = visible ? &jetbrains_mono_42 : &jetbrains_mono_76;
196+
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font);
197+
lv_obj_set_height(time, font->line_height);
198+
lv_obj_realign(msecTime);
199+
hoursVisible = visible;
200+
}
201+
}
202+
198203
void StopWatch::Refresh() {
199204
if (stopWatchController.IsRunning()) {
200205
RenderTime();

src/displayapp/screens/StopWatch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ namespace Pinetime::Applications {
3939
void RenderPause();
4040
void RenderLaps();
4141

42+
void SetHoursVisible(bool visible);
43+
4244
Pinetime::System::WakeLock wakeLock;
4345
Controllers::StopWatchController& stopWatchController;
4446
TickType_t blinkTime = 0;
4547
static constexpr int displayedLaps = 2;
4648
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
4749
lv_obj_t* lapText;
48-
bool isHoursLabelUpdated = false;
50+
bool hoursVisible = false;
4951

5052
lv_task_t* taskRefresh;
5153
};

0 commit comments

Comments
 (0)