diff --git a/modules/ui_shared/include/ui/screens/gps/gps_page_runtime.h b/modules/ui_shared/include/ui/screens/gps/gps_page_runtime.h index 3daf35cd..3ea0d003 100644 --- a/modules/ui_shared/include/ui/screens/gps/gps_page_runtime.h +++ b/modules/ui_shared/include/ui/screens/gps/gps_page_runtime.h @@ -8,5 +8,7 @@ namespace gps::ui::runtime bool is_available(); void enter(const shell::Host* host, lv_obj_t* parent); void exit(lv_obj_t* parent); +void remember_gps_view_state(); +bool restore_gps_view_state(); } // namespace gps::ui::runtime diff --git a/modules/ui_shared/src/ui/screens/gps/gps_page_runtime.cpp b/modules/ui_shared/src/ui/screens/gps/gps_page_runtime.cpp index 9a13587b..fc6251e5 100644 --- a/modules/ui_shared/src/ui/screens/gps/gps_page_runtime.cpp +++ b/modules/ui_shared/src/ui/screens/gps/gps_page_runtime.cpp @@ -87,6 +87,20 @@ static lv_obj_t* gps_root = nullptr; namespace { +struct SavedGpsMapView +{ + bool valid = false; + int zoom_level = gps_ui::kDefaultZoom; + double lat = gps_ui::kDefaultLat; + double lng = gps_ui::kDefaultLng; + bool has_fix = false; + int pan_x = 0; + int pan_y = 0; + bool follow_position = true; +}; + +SavedGpsMapView s_saved_gps_map_view; + void assign_layout_widgets(const gps::ui::layout::Widgets& w) { gps_root = w.root; @@ -379,6 +393,35 @@ bool is_available() return platform::ui::device::gps_supported(); } +void remember_gps_view_state() +{ + s_saved_gps_map_view.valid = true; + s_saved_gps_map_view.zoom_level = g_gps_state.zoom_level; + s_saved_gps_map_view.lat = g_gps_state.lat; + s_saved_gps_map_view.lng = g_gps_state.lng; + s_saved_gps_map_view.has_fix = g_gps_state.has_fix; + s_saved_gps_map_view.pan_x = g_gps_state.pan_x; + s_saved_gps_map_view.pan_y = g_gps_state.pan_y; + s_saved_gps_map_view.follow_position = g_gps_state.follow_position; +} + +bool restore_gps_view_state() +{ + if (!s_saved_gps_map_view.valid) + { + return false; + } + + g_gps_state.zoom_level = s_saved_gps_map_view.zoom_level; + g_gps_state.lat = s_saved_gps_map_view.lat; + g_gps_state.lng = s_saved_gps_map_view.lng; + g_gps_state.has_fix = s_saved_gps_map_view.has_fix; + g_gps_state.pan_x = s_saved_gps_map_view.pan_x; + g_gps_state.pan_y = s_saved_gps_map_view.pan_y; + g_gps_state.follow_position = s_saved_gps_map_view.follow_position; + return true; +} + void enter(const shell::Host* host, lv_obj_t* parent) { s_host = host; @@ -463,6 +506,18 @@ void enter(const shell::Host* host, lv_obj_t* parent) } init_gps_state_defaults(); + const bool restored_view = restore_gps_view_state(); + if (restored_view) + { + GPS_FLOW_LOG("[GPS][MAP][flow] restored view zoom=%d fix=%d follow=%d pan=%d,%d lat=%.6f lng=%.6f\n", + g_gps_state.zoom_level, + g_gps_state.has_fix, + g_gps_state.follow_position, + g_gps_state.pan_x, + g_gps_state.pan_y, + g_gps_state.lat, + g_gps_state.lng); + } hide_pan_h_indicator(); hide_pan_v_indicator(); @@ -547,6 +602,7 @@ void exit(lv_obj_t* parent) g_gps_state.alive, g_gps_state.exiting, gps_root); // Prevent re-entrant exit. + remember_gps_view_state(); g_gps_state.exiting = true; gps_runtime_pump().setActive(false); @@ -980,6 +1036,15 @@ bool is_available() return platform::ui::device::gps_supported(); } +void remember_gps_view_state() +{ +} + +bool restore_gps_view_state() +{ + return s_map_view_initialized; +} + void enter(const shell::Host* host, lv_obj_t* parent) { s_host = host; diff --git a/platform/esp/arduino_common/src/ui/screens/gps/gps_page_input.cpp b/platform/esp/arduino_common/src/ui/screens/gps/gps_page_input.cpp index 2abdde0e..078d9198 100644 --- a/platform/esp/arduino_common/src/ui/screens/gps/gps_page_input.cpp +++ b/platform/esp/arduino_common/src/ui/screens/gps/gps_page_input.cpp @@ -8,6 +8,7 @@ #include "ui/screens/gps/gps_modal.h" #include "ui/screens/gps/gps_page_lifetime.h" #include "ui/screens/gps/gps_page_map.h" +#include "ui/screens/gps/gps_page_runtime.h" #include "ui/screens/gps/gps_route_overlay.h" #include "ui/screens/gps/gps_state.h" #include "ui/screens/gps/gps_tracker_overlay.h" @@ -304,6 +305,7 @@ static void handle_map_touch_move(lv_indev_t* indev, const lv_point_t& point) g_gps_state.pan_y = new_pan_y; g_gps_state.follow_position = false; g_gps_state.pending_refresh = false; + gps::ui::runtime::remember_gps_view_state(); update_map_tiles(false); GPS_FLOW_LOG("[GPS][MAP][touch] drag_move dx=%d dy=%d pan=%d,%d->%d,%d\n", dx, @@ -558,6 +560,7 @@ static void refresh_map_after_pan_step() extern void update_map_tiles(bool lightweight); g_gps_state.pending_refresh = false; + gps::ui::runtime::remember_gps_view_state(); update_map_tiles(false); log_map_tile_state("pan_step"); } @@ -1123,6 +1126,7 @@ static void action_position_center() g_gps_state.pan_x = 0; g_gps_state.pan_y = 0; g_gps_state.follow_position = true; + gps::ui::runtime::remember_gps_view_state(); // Create or update GPS marker create_gps_marker(); @@ -1338,6 +1342,7 @@ void zoom_popup_apply_selection() g_gps_state.last_resolution_zoom = g_gps_state.zoom_level; g_gps_state.last_resolution_lat = g_gps_state.lat; + gps::ui::runtime::remember_gps_view_state(); update_resolution_display(); update_map_anchor(); diff --git a/platform/esp/arduino_common/src/ui/screens/gps/gps_page_map.cpp b/platform/esp/arduino_common/src/ui/screens/gps/gps_page_map.cpp index d406dacd..10431fc6 100644 --- a/platform/esp/arduino_common/src/ui/screens/gps/gps_page_map.cpp +++ b/platform/esp/arduino_common/src/ui/screens/gps/gps_page_map.cpp @@ -14,6 +14,7 @@ #include "ui/screens/gps/gps_constants.h" #include "ui/screens/gps/gps_page_components.h" #include "ui/screens/gps/gps_page_lifetime.h" +#include "ui/screens/gps/gps_page_runtime.h" #include "ui/screens/gps/gps_page_styles.h" #include "ui/screens/gps/gps_state.h" #include "ui/screens/gps/gps_tracker_overlay.h" @@ -1560,6 +1561,7 @@ void tick_gps_update(bool allow_map_refresh) gps_map_transform(g_gps_state.lat, g_gps_state.lng, map_lat, map_lon); g_gps_state.last_resolution_lat = map_lat; update_map_tiles(false); + gps::ui::runtime::remember_gps_view_state(); last_refresh_lat = new_lat; last_refresh_lng = new_lng; diff --git a/platform/esp/arduino_common/src/ui/screens/gps/gps_route_overlay.cpp b/platform/esp/arduino_common/src/ui/screens/gps/gps_route_overlay.cpp index c8837d11..f48bd542 100644 --- a/platform/esp/arduino_common/src/ui/screens/gps/gps_route_overlay.cpp +++ b/platform/esp/arduino_common/src/ui/screens/gps/gps_route_overlay.cpp @@ -7,6 +7,7 @@ #include "ui/screens/gps/gps_page_components.h" #include "ui/screens/gps/gps_page_lifetime.h" #include "ui/screens/gps/gps_page_map.h" +#include "ui/screens/gps/gps_page_runtime.h" #include "ui/screens/gps/gps_state.h" #include "ui/support/lvgl_fs_utils.h" #include "ui/widgets/map/map_tiles.h" @@ -596,6 +597,7 @@ bool gps_route_focus(bool show_fail_toast) reset_title_status_cache(); update_title_and_status(); update_resolution_display(); + gps::ui::runtime::remember_gps_view_state(); update_map_tiles(false); if (g_gps_state.map) @@ -668,4 +670,4 @@ void gps_route_draw_event(lv_event_t* e) void gps_route_cleanup() { clear_route_state(); -} \ No newline at end of file +} diff --git a/platform/esp/arduino_common/src/ui/screens/gps/gps_tracker_overlay.cpp b/platform/esp/arduino_common/src/ui/screens/gps/gps_tracker_overlay.cpp index aac7a969..2f6cb7a5 100644 --- a/platform/esp/arduino_common/src/ui/screens/gps/gps_tracker_overlay.cpp +++ b/platform/esp/arduino_common/src/ui/screens/gps/gps_tracker_overlay.cpp @@ -6,6 +6,7 @@ #include "ui/screens/gps/gps_modal.h" #include "ui/screens/gps/gps_page_lifetime.h" #include "ui/screens/gps/gps_page_map.h" +#include "ui/screens/gps/gps_page_runtime.h" #include "ui/screens/gps/gps_page_styles.h" #include "ui/screens/gps/gps_state.h" #include "ui/support/lvgl_fs_utils.h" @@ -351,6 +352,7 @@ void apply_tracker_view_defaults() reset_title_status_cache(); update_title_and_status(); update_resolution_display(); + gps::ui::runtime::remember_gps_view_state(); update_map_tiles(false); if (state.map)