on master help sign in
Document the basic input functions.
commit9b1fa9683b651a3ecd5265efe7fbce24fca11177 authorevancz <info@elm-lang.org> dateFri 17 May 2013, 23:13 (13 years ago) parent706d706
1 file changed+15−2
libraries/Graphics/Input.elm+15−2
libraries/Graphics/Input.elm+15−2
@@ -8,6 +8,8 @@ id x = x
88
99buttons : a -> { button : a -> String -> Element, events : Signal a }
1010
11+-- Create a button with a given label. The result is an `Element` and
12+-- a signal of units. This signal triggers whenever the button is pressed.
1113button : String -> (Element, Signal ())
1214button txt =
1315 let pool = N.buttons ()
@@ -16,6 +18,9 @@ button txt =
1618customButtons : a -> { button : a -> Element -> Element -> Element -> Element,
1719 events : Signal a }
1820
21+-- Create a button with custom states for up, hovering, and down
22+-- (given in that order). The result is an `Element` and
23+-- a signal of units. This signal triggers whenever the button is pressed.
1924customButton : Element -> Element -> Element -> (Element, Signal ())
2025customButton up hover down =
2126 let pool = N.customButtons ()
@@ -23,6 +28,9 @@ customButton up hover down =
2328
2429checkboxes : a -> { box : (Bool -> a) -> Bool -> Element, events : Signal a }
2530
31+-- Create a checkbox with a given start state. Notice that the result is a *signal*
32+-- of elements. That is because a checkbox has state that updates based on user input.
33+-- The boolean signal represents the current state of the checkbox.
2634checkbox : Bool -> (Signal Element, Signal Bool)
2735checkbox b =
2836 let cbs = N.checkboxes b
@@ -35,19 +43,24 @@ fields : a -> { field : (FieldState -> a) -> String -> FieldState -> Element,
3543
3644empty = { string="", start=0, end=0 }
3745
46+-- Create a field with the given default text. The output is an element that
47+-- updates to match the user input and a signal of strings representing the
48+-- content of the field.
3849field : String -> (Signal Element, Signal String)
3950field placeHolder =
4051 let tfs = N.fields empty
4152 in (lift (tfs.field id placeHolder) tfs.events, lift .string tfs.events)
4253
54+-- Same as `field` but the UI element blocks out each characters.
4355password : String -> (Signal Element, Signal String)
4456password placeHolder =
4557 let tfs = N.passwords empty
4658 in (lift (tfs.field id placeHolder) tfs.events, lift .string tfs.events)
4759
60+-- Same as `field` but it adds an annotation that this field is for email addresses.
61+-- This is helpful for auto-complete and for mobile users who may get a custom keyboard
62+-- with an `@` and `.com` button.
4863email : String -> (Signal Element, Signal String)
4964email placeHolder =
5065 let tfs = N.emails empty
5166 in (lift (tfs.field id placeHolder) tfs.events, lift .string tfs.events)
52−
53−-- file?