commit 455c3f50c60e16f067f740d49076b896342c9276
parent 0d60cc11cc6cbb226eff28c81fa5ab93f33920b4
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 29 May 2025 21:13:19 +0100
use register-widget more, fewer arrow widget repaints
Diffstat:
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl
@@ -126,12 +126,11 @@ label.readout {
})))
(fn readout [name text]
- (let [w
- (doto (Gtk.Label {:label text : name})
- (-> (: :get_style_context)
- (: :add_class :readout)))]
- (tset state-widgets name w)
- w))
+ (register-widget
+ name
+ (doto (Gtk.Label {:label text : name})
+ (-> (: :get_style_context)
+ (: :add_class :readout)))))
(local knot-in-m-s
(/ 1852 ; metres in nautical mile
@@ -157,6 +156,7 @@ label.readout {
: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)))
)))
@@ -174,25 +174,26 @@ label.readout {
(: :add (readout :speed "0"))))
(fn arrow []
- (let [height 40
- w (Gtk.Label {
- :halign Gtk.Align.CENTER
- :valign Gtk.Align.CENTER
- :width height :height height
- :on_draw
- (fn [self g]
- (g:set_source_rgb 0.4 0.0 0.1)
- (g:translate (// height 2) (// height 2))
- (g:rotate (/ (* -2 app-state.course math.pi) 360) )
- (g:translate (// height -2) (// height -2))
- (g:set_line_width 4)
- (g:move_to 10 height)
- (g:line_to (// height 2) 0)
- (g:line_to (- height 10) height)
- (g:fill)
- true)
- })]
- w))
+ (let [height 40]
+ (register-widget
+ :arrow
+ (Gtk.Label {
+ :halign Gtk.Align.CENTER
+ :valign Gtk.Align.CENTER
+ :width height :height height
+ :on_draw
+ (fn [self g]
+ (g:set_source_rgb 0.4 0.0 0.1)
+ (g:translate (// height 2) (// height 2))
+ (g:rotate (/ (* -2 app-state.course math.pi) 360) )
+ (g:translate (// height -2) (// height -2))
+ (g:set_line_width 4)
+ (g:move_to 10 height)
+ (g:line_to (// height 2) 0)
+ (g:line_to (- height 10) height)
+ (g:fill)
+ true)
+ }))))
(local socket-path (or (. arg 1) "/var/run/gnss-share.sock"))