invalidate map only when app-state changes

This commit is contained in:
Daniel Barlow 2025-05-29 21:09:24 +01:00
parent cb0314d1d6
commit f64bfeb7fd

View File

@ -76,11 +76,9 @@ label.readout {
;; to fill the width of the screen plus a bit
(fn cairo-the-map [self g]
(: (self:get_window) :invalidate_rect nil)
(let [{ : lat : lon : zoom } app-state
num-tiles-x (+ 0 (math.ceil (/ map-width tile-size)))
num-tiles-y (+ 0 (math.ceil (/ map-height tile-size)))
; _ (print app-state.lat app-state.lon)
(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom)
min-tile-x (math.floor (- tile-x (/ num-tiles-x 2)))
max-tile-x (math.ceil (+ tile-x (/ num-tiles-x 2)))
@ -115,12 +113,17 @@ label.readout {
(g:stroke)
true))
(fn register-widget [name widget]
(tset state-widgets name widget)
widget)
(fn osm-widget []
(Gtk.DrawingArea {
:width map-width :height map-height
:on_draw cairo-the-map
}))
(register-widget
:osm
(Gtk.DrawingArea {
:width map-width :height map-height
:on_draw cairo-the-map
})))
(fn readout [name text]
(let [w
@ -153,7 +156,7 @@ label.readout {
(case name
:speed (widget:set_label
(string.format "%.1f km/h" (* app-state.speed 3.6)))
:osm (widget:set_center app-state.lat app-state.lon)
:osm (: (widget:get_window) :invalidate_rect nil)
:time (widget:set_label
(hhmmss (+ utc-offset app-state.time-of-day)))
)))