-
Notifications
You must be signed in to change notification settings - Fork 15
/
Inputs.elm
41 lines (32 loc) · 1.29 KB
/
Inputs.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
29
30
31
32
33
34
35
36
37
38
39
40
41
module Inputs (field, remove, actions, fieldContent) where
{-| Create the Signals and Inputs needed to model interaction in this program.
The Inputs we create will provide handles for our display to give us new
events, and from there, it will provide data to update our program.
-}
import Graphics.Input (Input, input)
import Graphics.Input.Field as Field
import Keyboard
import Model (Action(Add, Remove))
---- Inputs ----
{-| An Input to keep track of the primary text field. -}
field : Input Field.Content
field = input Field.noContent
{-| An Input to keep track of requests to remove tasks. -}
remove : Input Int
remove = input 0
---- Useful Signals ----
{-| Current content of the primary input field. Normally uses whatever the user
types in, but if the user presses enter it clears the field.
-}
fieldContent : Signal Field.Content
fieldContent =
merge field.signal (always Field.noContent <~ entered)
{-| Merge all UI inputs into Actions. -}
actions : Signal Action
actions = merge (Add <~ sampleOn entered (.string <~ field.signal))
(Remove <~ remove.signal)
{-| Signal that updates when the enter key is pressed. We will use it to sample
other signals. Actual value of this signal is not important.
-}
entered : Signal ()
entered = always () <~ keepIf identity True Keyboard.enter