on master help sign in
Rename some stuff in Graphics.Input
3f8ce38evancz
compiler/Types/Alias.hs+2−2
@@ -12,7 +12,7 @@ import Types.Types
12builtins :: [(String,([X],Type))]
12builtins :: [(String,([X],Type))]
13builtins =
13builtins =
14 let touch = ("t0", time) : map (flip (,) int) ["x","y","x0","y0","id"]
14 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)]
16 line = [("color", tipe "Color"), ("width", float),
16 line = [("color", tipe "Color"), ("width", float),
17 ("cap", tipe "LineCap"), ("join", tipe "LineJoin"),
17 ("cap", tipe "LineCap"), ("join", tipe "LineJoin"),
18 ("miterLimit", float), ("dashing", listOf int),
18 ("miterLimit", float), ("dashing", listOf int),
@@ -23,7 +23,7 @@ builtins =
23 ("Time", ([], float)),
23 ("Time", ([], float)),
24 ("KeyCode", ([], int)),
24 ("KeyCode", ([], int)),
25 ("Touch", ([], makeRecord touch)),
25 ("Touch", ([], makeRecord touch)),
26− ("TextState", ([], makeRecord state)),
26+ ("FieldState", ([], makeRecord state)),
27 ("LineStyle", ([], makeRecord line))
27 ("LineStyle", ([], makeRecord line))
28 ]
28 ]
29
29
libraries/Graphics/Input.elm+18−16
@@ -21,31 +21,33 @@ customButton up hover down =
21 let pool = N.customButtons ()
21 let pool = N.customButtons ()
22 in (pool.button () up hover down, pool.events)
22 in (pool.button () up hover down, pool.events)
23
23
24−checkBoxes : a -> { box : (Bool -> a) -> Bool -> Element, events : Signal a }
24+checkboxes : a -> { box : (Bool -> a) -> Bool -> Element, events : Signal a }
25
25
26−checkBox : Bool -> (Signal Element, Signal Bool)
26+checkbox : Bool -> (Signal Element, Signal Bool)
27−checkBox b =
27+checkbox b =
28− let cbs = N.checkBoxes b
28+ let cbs = N.checkboxes b
29 in (lift (cbs.box id) cbs.events, cbs.events)
29 in (lift (cbs.box id) cbs.events, cbs.events)
30
30
31−type TextState = { text:String, start:Int, end:Int }
31+type FieldState = { string:String, start:Int, end:Int }
32
32
33−textFields : a -> { field : (TextState -> a) -> String -> TextState -> Element,
33+fields : a -> { field : (FieldState -> a) -> String -> FieldState -> Element,
34− events : Signal a }
34+ events : Signal a }
35
35
36+empty = { string="", start=0, end=0 }
37+
36−text : String -> TextState -> (Signal Element, Signal TextState)
38+field : String -> (Signal Element, Signal FieldState)
37−text placeHolder textState =
39+field placeHolder =
38− let tfs = N.textFields textState
40+ let tfs = N.fields empty
39 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
41 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
40
42
41−password : String -> TextState -> (Signal Element, Signal TextState)
43+password : String -> (Signal Element, Signal FieldState)
42−password placeHolder textState =
44+password placeHolder =
43− let tfs = N.passwords textState
45+ let tfs = N.passwords empty
44 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
46 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
45
47
46−email : String -> TextState -> (Signal Element, Signal TextState)
48+email : String -> (Signal Element, Signal FieldState)
47−email placeHolder textState =
49+email placeHolder =
48− let tfs = N.emails textState
50+ let tfs = N.emails empty
49 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
51 in (lift (tfs.field id placeHolder) tfs.events, tfs.events)
50
52
51-- file?
53-- file?
libraries/Native/Graphics/Input.js+7−6
@@ -108,7 +108,7 @@ Elm.Native.Graphics.Input = function(elm) {
108 }
108 }
109
109
110
110
111− function checkBoxes(defaultValue) {
111+ function checkboxes(defaultValue) {
112 var events = Signal.constant(defaultValue);
112 var events = Signal.constant(defaultValue);
113
113
114 function render(model) {
114 function render(model) {
@@ -141,7 +141,7 @@ Elm.Native.Graphics.Input = function(elm) {
141 return { _:{}, box:F2(box), events:events };
141 return { _:{}, box:F2(box), events:events };
142 }
142 }
143
143
144− function mkTextPool(type) { return function textFields(defaultValue) {
144+ function mkTextPool(type) { return function fields(defaultValue) {
145 var events = Signal.constant(defaultValue);
145 var events = Signal.constant(defaultValue);
146
146
147 function render(model) {
147 function render(model) {
@@ -151,7 +151,7 @@ Elm.Native.Graphics.Input = function(elm) {
151 field.id = 'test';
151 field.id = 'test';
152 field.type = type;
152 field.type = type;
153 field.placeholder = fromString(model.placeHolder);
153 field.placeholder = fromString(model.placeHolder);
154− field.value = fromString(model.state.input);
154+ field.value = fromString(model.state.string);
155 field.setSelectionRange(model.state.start, model.state.end);
155 field.setSelectionRange(model.state.start, model.state.end);
156 field.style.border = 'none';
156 field.style.border = 'none';
157
157
@@ -163,7 +163,7 @@ Elm.Native.Graphics.Input = function(elm) {
163 end = field.selectionStart;
163 end = field.selectionStart;
164 }
164 }
165 var state = { _:{},
165 var state = { _:{},
166− input:toString(field.value),
166+ string:toString(field.value),
167 start:start,
167 start:start,
168 end:end };
168 end:end };
169 elm.notify(events.id, field.elmHandler(state));
169 elm.notify(events.id, field.elmHandler(state));
@@ -184,7 +184,7 @@ Elm.Native.Graphics.Input = function(elm) {
184
184
185 function update(node, oldModel, newModel) {
185 function update(node, oldModel, newModel) {
186 node.elmHandler = newModel.handler;
186 node.elmHandler = newModel.handler;
187− node.value = fromString(newModel.state.input);
187+ node.value = fromString(newModel.state.string);
188 if (newModel.state.start <= newModel.state.end) {
188 if (newModel.state.start <= newModel.state.end) {
189 node.setSelectionRange(newModel.state.start, newModel.state.end);
189 node.setSelectionRange(newModel.state.start, newModel.state.end);
190 } else {
190 } else {
@@ -212,7 +212,8 @@ Elm.Native.Graphics.Input = function(elm) {
212 return elm.Native.Graphics.Input = {
212 return elm.Native.Graphics.Input = {
213 buttons:buttons,
213 buttons:buttons,
214 customButtons:customButtons,
214 customButtons:customButtons,
215+ checkboxes:checkboxes,
215− textFields:mkTextPool('text'),
216+ fields:mkTextPool('text'),
216 emails:mkTextPool('email'),
217 emails:mkTextPool('email'),
217 passwords:mkTextPool('password')
218 passwords:mkTextPool('password')
218 };
219 };