#include "ui_navigation.h" #include "esp_log.h" #include "screens.h" #include "ui.h" static void screen_gesture_cb(lv_event_t *event) { lv_indev_t *input = lv_indev_get_act(); if (!input || lv_dropdown_is_open(objects.history_metric) || lv_dropdown_is_open(objects.dim_timeout)) return; lv_obj_t *screen = lv_event_get_current_target(event); lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device}; unsigned index = 0; while (index < 4 && screens[index] != screen) ++index; if (index >= 4) return; lv_dir_t direction = lv_indev_get_gesture_dir(input); unsigned next = index; if (direction == LV_DIR_LEFT && index < 3) ++next; else if (direction == LV_DIR_RIGHT && index > 0) --next; if (next == index) return; lv_indev_wait_release(input); loadScreen((enum ScreensEnum)(next + 1)); ESP_LOGI("ui_navigation", "Swipe: page %u -> %u", index + 1, next + 1); } static void prepare_gestures(lv_obj_t *object) { lv_obj_clear_flag(object, LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_flag(object, LV_OBJ_FLAG_GESTURE_BUBBLE); for (uint32_t i = 0; i < lv_obj_get_child_cnt(object); ++i) prepare_gestures(lv_obj_get_child(object, i)); } void ui_navigation_init(void) { lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device}; for (unsigned i = 0; i < 4; ++i) { prepare_gestures(screens[i]); lv_obj_clear_flag(screens[i], LV_OBJ_FLAG_GESTURE_BUBBLE); lv_obj_add_event_cb(screens[i], screen_gesture_cb, LV_EVENT_GESTURE, NULL); } /* Sliders/dropdowns own their gestures; changing brightness must not navigate. */ lv_obj_clear_flag(objects.brightness, LV_OBJ_FLAG_GESTURE_BUBBLE); lv_obj_clear_flag(objects.history_metric, LV_OBJ_FLAG_GESTURE_BUBBLE); lv_obj_clear_flag(objects.dim_timeout, LV_OBJ_FLAG_GESTURE_BUBBLE); ESP_LOGI("ui_navigation", "Ready: 4 pages / measurements, air, history, device"); }