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) {
uint32_t value = settingsController.GetStepsGoal();
if (object == btnPlus && (event == LV_EVENT_PRESSED)) {
value += 1000;
if (value <= 500000) {
settingsController.SetStepsGoal(value);
lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal());
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10);
}
int valueChange = 0;
if (event == LV_EVENT_SHORT_CLICKED) {
valueChange = 500;
} else if (event == LV_EVENT_LONG_PRESSED || event == LV_EVENT_LONG_PRESSED_REPEAT) {
valueChange = 1000;
} else {
return;
}
if (object == btnMinus && (event == LV_EVENT_PRESSED)) {
value -= 1000;
if (value >= 1000) {
if (object == btnPlus) {
value += valueChange;
} else if (object == btnMinus) {
value -= valueChange;
}
if (value >= 1000 && value <= 500000) {
settingsController.SetStepsGoal(value);
lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal());
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10);
}
lv_obj_realign(stepValue);
}
}