Skip to content

Commit

Permalink
show playing/paused as a toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Mar 11, 2024
1 parent 09c9895 commit 277a7b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/shimmers/common/ui/controls.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
:on-click cycle-mode}]
[:span {:style {:padding-left "1em"}} mode-desc (name mode)]])))

(defn toggle-button
[ui-state
{:keys [states mode-key on-change]
:or {states {false "Paused" true "Playing"}
on-change (fn [])}}]
(let [mode (get @ui-state mode-key)
toggle (fn []
(swap! ui-state update mode-key not)
(on-change))]
[:div
[:input {:type "button"
:value (str (get states mode))
:on-click toggle}]]))

(defn checkbox [settings label field-ref]
[:div.label-set {:key label}
[:input {:type "checkbox" :checked (get-in @settings field-ref)
Expand Down
2 changes: 1 addition & 1 deletion src/shimmers/sketches/mechanism.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
[:div.flexcols
[:div {:style {:width "20em"}}
(ctrl/change-mode ui-state system-modes)
(ctrl/checkbox ui-state "Running?" [:running])
(ctrl/toggle-button ui-state {:mode-key :running})
(ctrl/checkbox ui-state "Show Angle/Path" [:show-angle-path])
(ctrl/numeric ui-state "Diametral Pitch" [:diametral-pitch] [0.05 1.0 0.01])
(ctrl/numeric ui-state "Driver Teeth" [:driver-teeth] [10 64 1])
Expand Down

0 comments on commit 277a7b0

Please sign in to comment.