diff --git a/scratches/bootstrap.clj b/scratches/bootstrap.clj index b5587ad..0d9c783 100644 --- a/scratches/bootstrap.clj +++ b/scratches/bootstrap.clj @@ -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.]})) diff --git a/src/age_of_sail/core.clj b/src/age_of_sail/core.clj index 01f0081..2fcf84d 100644 --- a/src/age_of_sail/core.clj +++ b/src/age_of_sail/core.clj @@ -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]