-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collapse.elm
47 lines (36 loc) · 1.61 KB
/
Collapse.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
42
43
44
45
46
47
module Collapse where
import Automaton
import Graphics.Element
import Graphics.Input
import Mouse
import Time
import Signal
segment = flow down [plainText "World!",
plainText "I love",
plainText "Stacy"]
move2 : (Int,Int) -> (Bool,Time.Time) -> Int -> Int
move2 (bottom,top) (click,_) value =
let goal = if click then top else bottom
in case compare value goal of
GT -> value - 1
LT -> value + 1
EQ -> value
tuple a b = (a,b)
collapsible : Element -> Element -> Int -> Element
collapsible title es = let box = flow down [title,es]
in (\h -> container (widthOf box) h topLeft box)
makeTitle : String -> (Element, Signal ())
makeTitle titleString = Graphics.Input.customButton (plainText titleString) (plainText titleString) (plainText titleString)
slider : Int -> Int -> Automaton.Automaton (Bool,Time.Time) Int
slider hTitle hBox = Automaton.state hTitle (move2 (hTitle,hBox))
clickTimer : Signal () -> Signal (Bool,Time.Time)
clickTimer titleButton = lift2 tuple (signalFlipper titleButton)
(Time.every (15 * millisecond))
flipper : a -> Bool -> (Bool,Bool)
flipper _ state = (not state, not state)
signalFlipper : Signal a -> Signal Bool
signalFlipper = Automaton.run (Automaton.hiddenState False flipper) False
collapsibleSignal : Element -> Int -> (Element,Signal Int)
collapsibleSignal titleElem body =
let (title,tb) = Graphics.Input.customButton titleElem titleElem titleElem
in (title,Automaton.run (slider (heightOf title) (heightOf title + body)) (heightOf title) (clickTimer tb))