-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
e29_text_formatter.clj
51 lines (46 loc) · 1.58 KB
/
e29_text_formatter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(ns e29-text-formatter
(:require [cljfx.api :as fx]))
(def *state
(atom {:name "Meepledorf"
:age 41}))
(defn labeled-input [{:keys [label input]}]
{:fx/type :v-box
:spacing 5
:children [{:fx/type :label
:text label}
input]})
(defn name-input [{:keys [value]}]
{:fx/type labeled-input
:label "Name"
:input {:fx/type :text-field
:text-formatter {:fx/type :text-formatter
:value-converter :default
:value value
:on-value-changed #(swap! *state assoc :name %)}}})
(defn age-input [{:keys [value]}]
{:fx/type labeled-input
:label "Age"
:input {:fx/type :text-field
:text-formatter {:fx/type :text-formatter
:value-converter :long
:value value
:on-value-changed #(swap! *state assoc :age %)}}})
(fx/mount-renderer
*state
(fx/create-renderer
:middleware
(fx/wrap-map-desc
(fn [{:keys [name age]}]
{:fx/type :stage
:showing true
:width 400
:scene {:fx/type :scene
:root {:fx/type :v-box
:padding 40
:spacing 20
:children [{:fx/type :label
:text (str name ", " age " y.o.")}
{:fx/type name-input
:value name}
{:fx/type age-input
:value age}]}}}))))