author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 02 Feb 2021 10:43:43 +0100 | |
branch | svghmi |
changeset 3120 | 7ecaefe38f6f |
parent 3118 | e704b0487515 |
child 3125 | 1fb0c07bd97b |
permissions | -rw-r--r-- |
2908 | 1 |
// widget_keypad.ysl2 |
2 |
||
2943
304e88bae115
SVGHMI: added more meaningful namespaces to emit javascript code from.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
3 |
emit "declarations:keypad" { |
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
4 |
| |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
5 |
| var keypads = { |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
6 |
foreach "$keypads_descs"{ |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
7 |
const "keypad_id","@id"; |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
8 |
foreach "arg"{ |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
9 |
const "g", "$geometry[@Id = $keypad_id]"; |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
10 |
| "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»], |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
11 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
12 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
13 |
| } |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
14 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
15 |
|
3010 | 16 |
template "widget[@type='Keypad']", mode="widget_class" |
17 |
|| |
|
18 |
class KeypadWidget extends Widget{ |
|
19 |
||
20 |
on_key_click(symbols) { |
|
21 |
var syms = symbols.split(" "); |
|
22 |
this.shift |= this.caps; |
|
23 |
this.editstr += syms[this.shift?syms.length-1:0]; |
|
24 |
this.shift = false; |
|
25 |
this.update(); |
|
26 |
} |
|
27 |
||
28 |
on_Esc_click() { |
|
29 |
end_modal.call(this); |
|
30 |
} |
|
31 |
||
32 |
on_Enter_click() { |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
33 |
let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr; |
3042
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
34 |
if(typeof coercedval == 'number' && isNaN(coercedval)){ |
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
35 |
// revert to initial so it explicitely shows input was ignored |
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
36 |
this.editstr = String(this.initial); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
37 |
this.update(); |
3042
ed43facc7137
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents:
3033
diff
changeset
|
38 |
} else { |
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
39 |
let callback_obj = this.result_callback_obj; |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
40 |
end_modal.call(this); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
41 |
callback_obj.edit_callback(coercedval); |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
42 |
} |
3010 | 43 |
} |
44 |
||
45 |
on_BackSpace_click() { |
|
46 |
this.editstr = this.editstr.slice(0,this.editstr.length-1); |
|
47 |
this.update(); |
|
48 |
} |
|
49 |
||
50 |
on_Sign_click() { |
|
51 |
if(this.editstr[0] == "-") |
|
52 |
this.editstr = this.editstr.slice(1,this.editstr.length); |
|
53 |
else |
|
54 |
this.editstr = "-" + this.editstr; |
|
55 |
this.update(); |
|
56 |
} |
|
57 |
||
58 |
on_NumDot_click() { |
|
59 |
if(this.editstr.indexOf(".") == "-1"){ |
|
60 |
this.editstr += "."; |
|
61 |
this.update(); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
on_Space_click() { |
|
66 |
this.editstr += " "; |
|
67 |
this.update(); |
|
68 |
} |
|
69 |
||
70 |
caps = false; |
|
71 |
_caps = undefined; |
|
72 |
on_CapsLock_click() { |
|
73 |
this.caps = !this.caps; |
|
74 |
this.update(); |
|
75 |
} |
|
76 |
||
77 |
shift = false; |
|
78 |
_shift = undefined; |
|
79 |
on_Shift_click() { |
|
80 |
this.shift = !this.shift; |
|
81 |
this.caps = false; |
|
82 |
this.update(); |
|
83 |
} |
|
84 |
editstr = ""; |
|
85 |
_editstr = undefined; |
|
86 |
result_callback_obj = undefined; |
|
87 |
start_edit(info, valuetype, callback_obj, initial,size) { |
|
88 |
show_modal.call(this,size); |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
89 |
this.editstr = String(initial); |
3010 | 90 |
this.result_callback_obj = callback_obj; |
91 |
this.Info_elt.textContent = info; |
|
92 |
this.shift = false; |
|
93 |
this.caps = false; |
|
3033
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
94 |
this.initial = initial; |
52f6548982d4
SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents:
3010
diff
changeset
|
95 |
|
3010 | 96 |
this.update(); |
97 |
} |
|
98 |
||
99 |
update() { |
|
100 |
if(this.editstr != this._editstr){ |
|
101 |
this._editstr = this.editstr; |
|
102 |
this.Value_elt.textContent = this.editstr; |
|
103 |
} |
|
3102
abb487b56911
SVGHMI: Fix bug in keypad leading to error messages in browser console when keypas has no Shift or CapsLock keys
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3047
diff
changeset
|
104 |
if(this.Shift_sub && this.shift != this._shift){ |
3010 | 105 |
this._shift = this.shift; |
106 |
(this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); |
|
107 |
} |
|
3102
abb487b56911
SVGHMI: Fix bug in keypad leading to error messages in browser console when keypas has no Shift or CapsLock keys
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3047
diff
changeset
|
108 |
if(this.CapsLock_sub && this.caps != this._caps){ |
3010 | 109 |
this._caps = this.caps; |
110 |
(this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
|| |
|
115 |
||
2908 | 116 |
template "widget[@type='Keypad']", mode="widget_defs" { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
117 |
param "hmi_element"; |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
118 |
labels("Esc Enter BackSpace Keys Info Value"); |
3118
e704b0487515
SVGHMI : removed support for changing keyboard position and showing at user defined location. Feature was problematic in many respect.
Edouard Tisserant
parents:
3102
diff
changeset
|
119 |
optional_labels("Sign Space NumDot"); |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2919
diff
changeset
|
120 |
activable_labels("CapsLock Shift"); |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2908
diff
changeset
|
121 |
| init: function() { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
122 |
foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" { |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
123 |
| id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')"); |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
124 |
} |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2919
diff
changeset
|
125 |
foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
126 |
| if(this.«.»_elt) |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
127 |
| this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()"); |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
128 |
} |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
129 |
| }, |
3010 | 130 |
| |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
131 |
const "g", "$geometry[@Id = $hmi_element/@id]"; |
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
132 |
| coordinates: [«$g/@x», «$g/@y»], |
2908 | 133 |
} |