on master help sign in
Add examples for all exported functions
a35f47fEvan Czaplicki
libraries/Graphics/Input.elm+27−2
@@ -33,8 +33,6 @@ import Signal (Signal)
33import Graphics.Element (Element)
33import Graphics.Element (Element)
34import Native.Graphics.Input
34import Native.Graphics.Input
35
35
36−data Handle a = Handle
37−
38{-| This is the key abstraction of this library. An `Input` is a record
36{-| This is the key abstraction of this library. An `Input` is a record
39of two fields:
37of two fields:
40
38
@@ -45,6 +43,8 @@ This will make more sense as you see more examples.
45-}
43-}
46type Input a = { signal : Signal a, handle : Handle a }
44type Input a = { signal : Signal a, handle : Handle a }
47
45
46+data Handle a = Handle
47+
48{-| Create a new `Input`. You just give the initial value for the
48{-| Create a new `Input`. You just give the initial value for the
49input’s `signal`.
49input’s `signal`.
50
50
@@ -78,9 +78,34 @@ users presses "2", `keys.signal` will update to `(Number 2)`.
78button : Handle a -> a -> String -> Element
78button : Handle a -> a -> String -> Element
79button = Native.Graphics.Input.button
79button = Native.Graphics.Input.button
80
80
81+{-| Same as `button` but lets you customize buttons to look however you want.
82+
83+ click : Input ()
84+ click = input ()
85+
86+ prettyButton : Element
87+ prettyButton =
88+ customButton click.handle
89+ (image 100 40 "/button_up.jpg")
90+ (image 100 40 "/button_hover.jpg")
91+ (image 100 40 "/button_down.jpg")
92+-}
81customButton : Handle a -> a -> Element -> Element -> Element -> Element
93customButton : Handle a -> a -> Element -> Element -> Element -> Element
82customButton = Native.Graphics.Input.customButton
94customButton = Native.Graphics.Input.customButton
83
95
96+{-| Create a checkbox. The following example creates three synced checkboxes:
97+
98+ check : Input Bool
99+ check = input False
100+
101+ boxes : Bool -> Element
102+ boxes checked =
103+ let box = container 40 40 middle (checkbox check.handle id checked)
104+ in flow right [ box, box, box ]
105+
106+ main : Signal Element
107+ main = boxes <~ check.signal
108+-}
84checkbox : Handle a -> (Bool -> a) -> Bool -> Element
109checkbox : Handle a -> (Bool -> a) -> Bool -> Element
85checkbox = Native.Graphics.Input.checkbox
110checkbox = Native.Graphics.Input.checkbox
86
111