on master help sign in
Rename some stuff in Graphics.Input
commit3f8ce38f819446fcb27575f08ac7a064d5bd3d77 authorevancz <info@elm-lang.org> dateMon 6 May 2013, 02:30 (13 years ago) parent80b47ed
3 files changed+27−24
compiler/Types/Alias.hs+2−2 libraries/Graphics/Input.elm+18−16 libraries/Native/Graphics/Input.js+7−6
compiler/Types/Alias.hs+2−2
@@ -12,7 +12,7 @@ import Types.Types
1212builtins :: [(String,([X],Type))]
1313builtins =
1414 let touch = ("t0", time) : map (flip (,) int) ["x","y","x0","y0","id"]
15− state = [("text", string), ("start", int), ("end", int)]
15+ state = [("string", string), ("start", int), ("end", int)]
1616 line = [("color", tipe "Color"), ("width", float),
1717 ("cap", tipe "LineCap"), ("join", tipe "LineJoin"),
1818 ("miterLimit", float), ("dashing", listOf int),
@@ -23,7 +23,7 @@ builtins =
2323 ("Time", ([], float)),
2424 ("KeyCode", ([], int)),
2525 ("Touch", ([], makeRecord touch)),
26− ("TextState", ([], makeRecord state)),
26+ ("FieldState", ([], makeRecord state)),
2727 ("LineStyle", ([], makeRecord line))
2828 ]
2929
libraries/Graphics/Input.elm+18−16
@@ -21,31 +21,33 @@ customButton up hover down =
2121 let pool = N.customButtons ()
2222 in (pool.button () up hover down, pool.events)
2323
24−checkBoxes : a -> { box : (Bool -> a) -> Bool -> Element, events : Signal a }
24+checkboxes : a -> { box : (Bool -> a) -> Bool -> Element, events : Signal a }
2525
26−checkBox : Bool -> (Signal Element, Signal Bool)
27−checkBox b =
28− let cbs = N.checkBoxes b
26+checkbox : Bool -> (Signal Element, Signal Bool)
27+checkbox b =
28+ let cbs = N.checkboxes b
2929 in (lift (cbs.box id) cbs.events, cbs.events)
3030
31−type TextState = { text:String, start:Int, end:Int }
31+type FieldState = { string:String, start:Int, end:Int }
3232
33−textFields : a -> { field : (TextState -> a) -> String -> TextState -> Element,
34− events : Signal a }
33+fields : a -> { field : (FieldState -> a) -> String -> FieldState -> Element,
34+ events : Signal a }
3535
36−text : String -> TextState -> (Signal Element, Signal TextState)
37−text placeHolder textState =
38− let tfs = N.textFields textState
36+empty = { string="", start=0, end=0 }
37+
38+field : String -> (Signal Element, Signal FieldState)
39+field placeHolder =
40+ let tfs = N.fields empty
3941 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
4042
41−password : String -> TextState -> (Signal Element, Signal TextState)
42−password placeHolder textState =
43− let tfs = N.passwords textState
43+password : String -> (Signal Element, Signal FieldState)
44+password placeHolder =
45+ let tfs = N.passwords empty
4446 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
4547
46−email : String -> TextState -> (Signal Element, Signal TextState)
47−email placeHolder textState =
48− let tfs = N.emails textState
48+email : String -> (Signal Element, Signal FieldState)
49+email placeHolder =
50+ let tfs = N.emails empty
4951 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
5052
5153-- file?
libraries/Native/Graphics/Input.js+7−6
@@ -108,7 +108,7 @@ Elm.Native.Graphics.Input = function(elm) {
108108 }
109109
110110
111− function checkBoxes(defaultValue) {
111+ function checkboxes(defaultValue) {
112112 var events = Signal.constant(defaultValue);
113113
114114 function render(model) {
@@ -141,7 +141,7 @@ Elm.Native.Graphics.Input = function(elm) {
141141 return { _:{}, box:F2(box), events:events };
142142 }
143143
144− function mkTextPool(type) { return function textFields(defaultValue) {
144+ function mkTextPool(type) { return function fields(defaultValue) {
145145 var events = Signal.constant(defaultValue);
146146
147147 function render(model) {
@@ -151,7 +151,7 @@ Elm.Native.Graphics.Input = function(elm) {
151151 field.id = 'test';
152152 field.type = type;
153153 field.placeholder = fromString(model.placeHolder);
154− field.value = fromString(model.state.input);
154+ field.value = fromString(model.state.string);
155155 field.setSelectionRange(model.state.start, model.state.end);
156156 field.style.border = 'none';
157157
@@ -163,7 +163,7 @@ Elm.Native.Graphics.Input = function(elm) {
163163 end = field.selectionStart;
164164 }
165165 var state = { _:{},
166− input:toString(field.value),
166+ string:toString(field.value),
167167 start:start,
168168 end:end };
169169 elm.notify(events.id, field.elmHandler(state));
@@ -184,7 +184,7 @@ Elm.Native.Graphics.Input = function(elm) {
184184
185185 function update(node, oldModel, newModel) {
186186 node.elmHandler = newModel.handler;
187− node.value = fromString(newModel.state.input);
187+ node.value = fromString(newModel.state.string);
188188 if (newModel.state.start <= newModel.state.end) {
189189 node.setSelectionRange(newModel.state.start, newModel.state.end);
190190 } else {
@@ -212,7 +212,8 @@ Elm.Native.Graphics.Input = function(elm) {
212212 return elm.Native.Graphics.Input = {
213213 buttons:buttons,
214214 customButtons:customButtons,
215− textFields:mkTextPool('text'),
215+ checkboxes:checkboxes,
216+ fields:mkTextPool('text'),
216217 emails:mkTextPool('email'),
217218 passwords:mkTextPool('password')
218219 };