Last active
December 30, 2018 20:42
-
-
Save tothda/697971ce569feb785317b6f696641aee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hiperk.jfx.checkbox-demo | |
(:require [fn-fx.fx-dom :as dom] | |
[fn-fx.diff :refer [component defui render should-update?]] | |
[fn-fx.controls :as ui])) | |
(defui Stage | |
(render [this {:keys [accepted?]}] | |
(ui/stage | |
:title "Checkbox Demo" | |
:shown true | |
:scene (ui/scene | |
:width 300 | |
:height 200 | |
:root (ui/v-box | |
:padding (ui/insets :top-right-bottom-left 10) | |
:spacing 10 | |
:children [(ui/h-box | |
:spacing 10 | |
:children [(ui/label :text "Terms") | |
(ui/check-box | |
:id ::checkbox | |
:on-action {:event :toggle | |
:fn-fx/include { | |
#_ #_ ::checkbox #{:selected} | |
:fn-fx/event #{:target} | |
}})]) | |
(ui/text | |
:fill (ui/color :value (if accepted? "green" "red")) | |
:text (if accepted? | |
"Terms are accepted." | |
"Terms are not accepted."))]))))) | |
(defn -main [] | |
(let [state (atom {:accepted? false}) | |
handler (fn [event] | |
(let [accepted? (-> event :fn-fx/includes :fn-fx/event :target .isSelected)] | |
(swap! state assoc :accepted? accepted?))) | |
ui-state (atom (dom/app (stage @state) handler))] | |
(add-watch state :ui (fn [k r os ns] | |
(swap! ui-state | |
(fn [old-ui-state] | |
(dom/update-app old-ui-state (stage ns)))))))) | |
(comment | |
(-main)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment