Some more UI, but I think I need to re-work bindings

This commit is contained in:
Dane Johnson 2023-11-06 13:30:43 -06:00
parent a270a2a806
commit 83159aef5e
2 changed files with 34 additions and 3 deletions

View File

@ -1,7 +1,7 @@
;; you should be in age-of-sail.core>
(def my-ship (ref {:position [0. 0.]
:name "Virgina Woolfe"
:name "Virginia Woolfe"
:heading (normalize [1.0 1.0])
:slots [{:type :downwind-sail :length 2 :furl 1.0}]
:velocity [1. 0.]}))

View File

@ -64,18 +64,49 @@
;; UI
(def tracked-ship (atom nil))
(defn ship-start-stop
[]
(letfn [(indicator [running] (if running "Stop" "Start"))
(toggle-prgm [_] (if @@program (stop-program) (start-program)))]
(let [btn (button :text (indicator @@program))]
(b/bind @program (b/transform indicator) (b/property btn :text))
(listen btn :mouse-clicked toggle-prgm)
btn)))
(defn ship-chooser
[]
(let [name (text :columns 20)]
(b/bind (.getDocument name) (b/transform #(find-ship @ships %)) tracked-ship)
(flow-panel :items ["Ship Name" name])))
(defn format-position
[ship]
(apply format "X: %.2f Y: %.2f" (:position @ship)))
(defn ship-info
[])
[]
(let [panel (vertical-panel :visible? false)
position (label)]
(b/bind tracked-ship (b/some identity)
(b/tee
(b/bind (b/transform format-position) (b/value position))))
(add! panel (flow-panel :items ["Position" position]))
panel))
(defn show-ui
[]
(-> (frame :title "Space Sim" :content (ship-chooser)) pack! show!))
(let [root (frame :title "Age of Sail" :content (vertical-panel))
start-stop (ship-start-stop)
chooser (ship-chooser)
info (ship-info)]
(b/bind tracked-ship (b/transform boolean) (b/tee (b/property info :visible?)
(b/b-do [_] (pack! root))))
(doto root
(add! start-stop)
(add! chooser)
(add! info)
pack!
show!)))
(defn -main
[args]