SettingSteps: Improve goal setting

Long pressing will change the value by 1000, whereas clicks will change
it by 500. This allows setting more precise values, while also making it
easier to set any value.
This commit is contained in:
Riku Isokoski 2023-02-01 11:53:06 +02:00
parent 4e1a2aff47
commit d4eb24b7f8

View File

@ -68,21 +68,25 @@ SettingSteps::~SettingSteps() {
void SettingSteps::UpdateSelected(lv_obj_t* object, lv_event_t event) { void SettingSteps::UpdateSelected(lv_obj_t* object, lv_event_t event) {
uint32_t value = settingsController.GetStepsGoal(); uint32_t value = settingsController.GetStepsGoal();
if (object == btnPlus && (event == LV_EVENT_PRESSED)) {
value += 1000; int valueChange = 0;
if (value <= 500000) { if (event == LV_EVENT_SHORT_CLICKED) {
settingsController.SetStepsGoal(value); valueChange = 500;
lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); } else if (event == LV_EVENT_LONG_PRESSED || event == LV_EVENT_LONG_PRESSED_REPEAT) {
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); valueChange = 1000;
} } else {
return;
} }
if (object == btnMinus && (event == LV_EVENT_PRESSED)) { if (object == btnPlus) {
value -= 1000; value += valueChange;
if (value >= 1000) { } else if (object == btnMinus) {
settingsController.SetStepsGoal(value); value -= valueChange;
lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); }
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10);
} if (value >= 1000 && value <= 500000) {
settingsController.SetStepsGoal(value);
lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal());
lv_obj_realign(stepValue);
} }
} }