-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFields.elm
28 lines (20 loc) · 1.21 KB
/
Fields.elm
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
module Fields where
import Util (getFloat)
import Graphics.Input (fields,emptyFieldState,FieldState)
import Automaton
group = fields ("Name","1.0")
sig = group.events
fieldMaker : {events:Signal (String,String),field:(FieldState->(String,String)) -> String -> FieldState ->Element } -> Int -> String -> String -> Element
fieldMaker group wide name dflt = flow right [width wide <| plainText name,
group.field
(\r -> (name,r.string))
name {string=dflt,selectionStart=0,selectionEnd=0}]
condenser (name,val) rec = case name of
"Test" -> {rec - test | test = getFloat val}
"Foo" -> {rec - foo | foo = getFloat val}
_ -> rec
updater : ((String,String) -> b -> b) -> b -> Signal (String,String) -> Signal b
updater f base = Automaton.run (Automaton.state base f) base
main = lift (flow down) <| combine [lift (plainText . show) <| updater condenser {test=3.14,foo=159.1} sig,
constant <| fieldMaker group 100 "Test" "3.14",
constant <| fieldMaker group 100 "Foo" "159.1"]