clobber map-surface when bounds change

This commit is contained in:
Daniel Barlow 2025-05-30 23:34:17 +01:00
parent acbe27e6e2
commit 195e028e22

View File

@ -71,7 +71,7 @@ label.readout {
(collect [k v (pairs table2) &into table1] (collect [k v (pairs table2) &into table1]
k v)) k v))
(var map-surface nil)
(fn map-bounds [lat lon zoom] (fn map-bounds [lat lon zoom]
(let [num-tiles-x (+ 1 (math.ceil (/ map-width tile-size))) (let [num-tiles-x (+ 1 (math.ceil (/ map-width tile-size)))
@ -122,6 +122,7 @@ label.readout {
(g:stroke) (g:stroke)
map-surface))) map-surface)))
(var map-surface nil)
(fn on-osm-draw [widget g] (fn on-osm-draw [widget g]
(when (not map-surface) (when (not map-surface)
@ -177,16 +178,24 @@ label.readout {
(fn update-app-state [new-vals] (fn update-app-state [new-vals]
(merge app-state new-vals) (let [old-bounds
(each [name widget (pairs state-widgets)] (map-bounds app-state.lat app-state.lon app-state.zoom)]
(case name (merge app-state new-vals)
:speed (widget:set_label (let [bounds
(string.format "%.1f km/h" (* app-state.speed 3.6))) (map-bounds app-state.lat app-state.lon app-state.zoom)]
:osm (: (widget:get_window) :invalidate_rect nil) (when (or
:arrow (: (widget:get_window) :invalidate_rect nil) (not (= old-bounds.min.x bounds.min.x))
:time (widget:set_label (not (= old-bounds.min.y bounds.min.y)))
(hhmmss (+ utc-offset app-state.time-of-day))) (set map-surface nil)))
))) (each [name widget (pairs state-widgets)]
(case name
:speed (widget:set_label
(string.format "%.1f km/h" (* app-state.speed 3.6)))
:osm (: (widget:get_window) :invalidate_rect nil)
:arrow (: (widget:get_window) :invalidate_rect nil)
:time (widget:set_label
(hhmmss (+ utc-offset app-state.time-of-day)))
))))
(fn readouts [] (fn readouts []