Skip to content

Commit 639fd3a

Browse files
committed
More tidying following review
1 parent 5789f15 commit 639fd3a

1 file changed

Lines changed: 88 additions & 85 deletions

File tree

src/displayapp/screens/settings/SettingPineTimeStyle.cpp

Lines changed: 88 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
using namespace Pinetime::Applications::Screens;
77

88
namespace {
9-
static void event_handler(lv_obj_t * obj, lv_event_t event) {
10-
SettingPineTimeStyle* screen = static_cast<SettingPineTimeStyle *>(obj->user_data);
9+
static void event_handler(lv_obj_t* obj, lv_event_t event) {
10+
SettingPineTimeStyle* screen = static_cast<SettingPineTimeStyle*>(obj->user_data);
1111
screen->UpdateSelected(obj, event);
1212
}
1313
}
1414

15-
SettingPineTimeStyle::SettingPineTimeStyle(
16-
Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Settings &settingsController) :
17-
Screen(app),
18-
settingsController{settingsController}
19-
{
15+
SettingPineTimeStyle::SettingPineTimeStyle(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
16+
: Screen(app), settingsController {settingsController} {
2017
timebar = lv_obj_create(lv_scr_act(), nullptr);
2118
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorBG()]);
2219
lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
@@ -140,7 +137,7 @@ SettingPineTimeStyle::SettingPineTimeStyle(
140137
lv_obj_set_style_local_line_opa(stepGauge, LV_GAUGE_PART_NEEDLE, LV_STATE_DEFAULT, LV_OPA_COVER);
141138
lv_obj_set_style_local_line_width(stepGauge, LV_GAUGE_PART_NEEDLE, LV_STATE_DEFAULT, 3);
142139
lv_obj_set_style_local_pad_inner(stepGauge, LV_GAUGE_PART_NEEDLE, LV_STATE_DEFAULT, 4);
143-
140+
144141
backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
145142
lv_obj_set_click(backgroundLabel, true);
146143
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
@@ -222,74 +219,79 @@ bool SettingPineTimeStyle::Refresh() {
222219
return running;
223220
}
224221

225-
void SettingPineTimeStyle::UpdateSelected(lv_obj_t *object, lv_event_t event) {
222+
void SettingPineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) {
226223
uint8_t valueTime = settingsController.GetPTSColorTime();
227224
uint8_t valueBar = settingsController.GetPTSColorBar();
228225
uint8_t valueBG = settingsController.GetPTSColorBG();
229-
230-
if((object == btnNextTime) && (event == LV_EVENT_PRESSED)) {
231-
if ( valueTime < 16 ) {
232-
valueTime += 1;
233-
} else {
234-
valueTime = 0;
226+
227+
if (event == LV_EVENT_CLICKED) {
228+
if (object == btnNextTime) {
229+
if (valueTime < 16) {
230+
valueTime += 1;
231+
} else {
232+
valueTime = 0;
233+
}
234+
settingsController.SetPTSColorTime(valueTime);
235+
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
236+
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
237+
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
235238
}
236-
settingsController.SetPTSColorTime(valueTime);
237-
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
238-
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
239-
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
240-
}
241-
if((object == btnPrevTime) && (event == LV_EVENT_PRESSED)) {
242-
if ( valueTime > 0 ) {
243-
valueTime -= 1;
244-
} else {
245-
valueTime = 16;
239+
if (object == btnPrevTime) {
240+
if (valueTime > 0) {
241+
valueTime -= 1;
242+
} else {
243+
valueTime = 16;
244+
}
245+
settingsController.SetPTSColorTime(valueTime);
246+
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
247+
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
248+
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
246249
}
247-
settingsController.SetPTSColorTime(valueTime);
248-
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
249-
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
250-
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
251-
}
252-
if((object == btnNextBar) && (event == LV_EVENT_PRESSED)) {
253-
if ( valueBar < 16 ) {
254-
valueBar += 1;
255-
// Avoid setting the sidebar black
256-
if ( valueBar == 3 ) { valueBar += 1; }
257-
} else {
258-
valueBar = 0;
250+
if (object == btnNextBar) {
251+
if (valueBar < 16) {
252+
valueBar += 1;
253+
// Avoid setting the sidebar black
254+
if (valueBar == 3) {
255+
valueBar += 1;
256+
}
257+
} else {
258+
valueBar = 0;
259+
}
260+
settingsController.SetPTSColorBar(valueBar);
261+
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
259262
}
260-
settingsController.SetPTSColorBar(valueBar);
261-
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
262-
}
263-
if((object == btnPrevBar) && (event == LV_EVENT_PRESSED)) {
264-
if ( valueBar > 0 ) {
265-
valueBar -= 1;
266-
// Avoid setting the sidebar black
267-
if ( valueBar == 3 ) { valueBar -= 1; }
268-
} else {
269-
valueBar = 16;
263+
if (object == btnPrevBar) {
264+
if (valueBar > 0) {
265+
valueBar -= 1;
266+
// Avoid setting the sidebar black
267+
if (valueBar == 3) {
268+
valueBar -= 1;
269+
}
270+
} else {
271+
valueBar = 16;
272+
}
273+
settingsController.SetPTSColorBar(valueBar);
274+
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
270275
}
271-
settingsController.SetPTSColorBar(valueBar);
272-
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
273-
}
274-
if((object == btnNextBG) && (event == LV_EVENT_PRESSED)) {
275-
if ( valueBG < 16 ) {
276-
valueBG += 1;
277-
} else {
278-
valueBG = 0;
276+
if (object == btnNextBG) {
277+
if (valueBG < 16) {
278+
valueBG += 1;
279+
} else {
280+
valueBG = 0;
281+
}
282+
settingsController.SetPTSColorBG(valueBG);
283+
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
279284
}
280-
settingsController.SetPTSColorBG(valueBG);
281-
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
282-
}
283-
if((object == btnPrevBG) && (event == LV_EVENT_PRESSED)) {
284-
if ( valueBG > 0 ) {
285-
valueBG -= 1;
286-
} else {
287-
valueBG = 16;
285+
if (object == btnPrevBG) {
286+
if (valueBG > 0) {
287+
valueBG -= 1;
288+
} else {
289+
valueBG = 16;
290+
}
291+
settingsController.SetPTSColorBG(valueBG);
292+
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
288293
}
289-
settingsController.SetPTSColorBG(valueBG);
290-
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
291-
}
292-
if((object == btnReset) && (event == LV_EVENT_PRESSED)) {
294+
if (object == btnReset) {
293295
settingsController.SetPTSColorTime(11);
294296
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
295297
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
@@ -298,25 +300,26 @@ void SettingPineTimeStyle::UpdateSelected(lv_obj_t *object, lv_event_t event) {
298300
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
299301
settingsController.SetPTSColorBG(3);
300302
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[3]);
301-
}
302-
if((object == btnRandom) && (event == LV_EVENT_PRESSED)) {
303-
uint8_t randTime = rand() % 17;
304-
uint8_t randBar = rand() % 17;
305-
uint8_t randBG = rand() % 17;
306-
// Check if the time color is the same as its background, or if the sidebar is black. If so, change them to more useful values.
307-
if (randTime == randBG) {
308-
randBG += 1;
309303
}
310-
if (randBar == 3) {
311-
randBar = randTime;
304+
if (object == btnRandom) {
305+
uint8_t randTime = rand() % 17;
306+
uint8_t randBar = rand() % 17;
307+
uint8_t randBG = rand() % 17;
308+
// Check if the time color is the same as its background, or if the sidebar is black. If so, change them to more useful values.
309+
if (randTime == randBG) {
310+
randBG += 1;
311+
}
312+
if (randBar == 3) {
313+
randBar = randTime;
314+
}
315+
settingsController.SetPTSColorTime(randTime);
316+
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
317+
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
318+
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
319+
settingsController.SetPTSColorBar(randBar);
320+
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBar]);
321+
settingsController.SetPTSColorBG(randBG);
322+
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBG]);
312323
}
313-
settingsController.SetPTSColorTime(randTime);
314-
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
315-
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
316-
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
317-
settingsController.SetPTSColorBar(randBar);
318-
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBar]);
319-
settingsController.SetPTSColorBG(randBG);
320-
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBG]);
321324
}
322325
}

0 commit comments

Comments
 (0)