From d4eb24b7f8d50990fcdcd4e4dcd4dbd3d1f212a2 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 1 Feb 2023 11:53:06 +0200 Subject: [PATCH] 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. --- .../screens/settings/SettingSteps.cpp | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSteps.cpp b/src/displayapp/screens/settings/SettingSteps.cpp index a6b6f4a8..8d756c1c 100644 --- a/src/displayapp/screens/settings/SettingSteps.cpp +++ b/src/displayapp/screens/settings/SettingSteps.cpp @@ -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) { - settingsController.SetStepsGoal(value); - lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); - lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); - } + 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_realign(stepValue); } }