/
e25_radio_buttons.clj
37 lines (33 loc) · 1.28 KB
/
e25_radio_buttons.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns e25-radio-buttons
(:require [cljfx.api :as fx]))
(def *option
(atom :a))
(defn radio-group [{:keys [options value on-action]}]
{:fx/type fx/ext-let-refs
:refs {::toggle-group {:fx/type :toggle-group}}
:desc {:fx/type :h-box
:padding 20
:spacing 10
:children (for [option options]
{:fx/type :radio-button
:toggle-group {:fx/type fx/ext-get-ref
:ref ::toggle-group}
:selected (= option value)
:text (str option)
:on-action (assoc on-action :option option)})}})
(def renderer
(fx/create-renderer
:opts {:fx.opt/map-event-handler
(fn [e]
(case (:event/type e)
::set-option (reset! *option (:option e))))}
:middleware (fx/wrap-map-desc
(fn [option]
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type radio-group
:options [:a :b :c]
:value option
:on-action {:event/type ::set-option}}}}))))
(fx/mount-renderer *option renderer)