commit 0d60cc11cc6cbb226eff28c81fa5ab93f33920b4
parent 8357aab222da57ff8cf753b70934a49610a691c5
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 29 May 2025 21:09:24 +0100
invalidate map only when app-state changes
Diffstat:
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl
@@ -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)))
)))