InfiniTime.git

commit d4eb24b7f8d50990fcdcd4e4dcd4dbd3d1f212a2

Author: Riku Isokoski <riksu9000@gmail.com>

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.

 src/displayapp/screens/settings/SettingSteps.cpp | 32 ++++++++++-------


diff --git a/src/displayapp/screens/settings/SettingSteps.cpp b/src/displayapp/screens/settings/SettingSteps.cpp
index a6b6f4a8be3939621f44d7bbcd6b51711d817bda..8d756c1c224a4ea06d3ef9d33383c769c0e3314e 100644
--- a/src/displayapp/screens/settings/SettingSteps.cpp
+++ b/src/displayapp/screens/settings/SettingSteps.cpp
@@ -68,21 +68,25 @@ }
 
 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);
   }
 }