1 // widget_input.ysl2 |
1 // widget_input.ysl2 |
|
2 |
|
3 template "widget[@type='Input']", mode="widget_class"{ |
|
4 || |
|
5 class InputWidget extends Widget{ |
|
6 on_op_click(opstr) { |
|
7 let new_val = this.change_hmi_value(0, opstr); |
|
8 } |
|
9 edit_callback(new_val) { |
|
10 this.apply_hmi_value(0, new_val); |
|
11 } |
|
12 } |
|
13 || |
|
14 } |
2 |
15 |
3 template "widget[@type='Input']", mode="widget_defs" { |
16 template "widget[@type='Input']", mode="widget_defs" { |
4 param "hmi_element"; |
17 param "hmi_element"; |
5 optional_labels("key_pos"); |
18 |
6 const "value_elt" { |
19 const "key_pos_elt" optional_labels("key_pos"); |
7 optional_labels("value"); |
20 value "$key_pos_elt"; |
8 } |
21 |
|
22 const "value_elt" optional_labels("value"); |
9 const "have_value","string-length($value_elt)>0"; |
23 const "have_value","string-length($value_elt)>0"; |
10 value "$value_elt"; |
24 value "$value_elt"; |
|
25 |
|
26 const "edit_elt" optional_labels("edit"); |
|
27 const "have_edit","string-length($edit_elt)>0"; |
|
28 value "$edit_elt"; |
|
29 |
11 if "$have_value" |
30 if "$have_value" |
12 | frequency: 5, |
31 | frequency: 5, |
13 | last_val: undefined, |
32 |
14 | dispatch: function(value) { |
33 | dispatch: function(value) { |
|
34 |
|
35 if "$have_edit" |
15 | this.last_val = value; |
36 | this.last_val = value; |
|
37 |
16 if "$have_value" |
38 if "$have_value" |
17 | this.value_elt.textContent = String(value); |
39 | this.value_elt.textContent = String(value); |
18 |
40 |
19 | }, |
41 | }, |
20 const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id"; |
42 |
21 | init: function() { |
43 | init: function() { |
22 if "$edit_elt_id" { |
44 |
23 | id("«$edit_elt_id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_edit_click()"); |
45 if "$have_edit" { |
|
46 | this.edit_elt.onclick = () => edit_value( |
|
47 | "«path/@value»", "«path/@type»", |
|
48 | this, this.last_val, |
|
49 choose { |
|
50 when "string-length($key_pos_elt)>0" |
|
51 | this.key_pos_elt.getBBox() |
|
52 otherwise |
|
53 | undefined |
|
54 } |
|
55 | ); |
24 } |
56 } |
|
57 |
25 foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { |
58 foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { |
26 | id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_op_click('«func:escape_quotes(@inkscape:label)»')"); |
59 | id("«@id»").onclick = () => this.on_op_click("«func:escape_quotes(@inkscape:label)»"); |
27 } |
60 } |
28 | }, |
|
29 | on_op_click: function(opstr) { |
|
30 | let new_val = this.change_hmi_value(0, opstr); |
|
31 // if "$have_value"{ |
|
32 // | this.value_elt.textContent = String(new_val); |
|
33 // /* TODO gray out value until refreshed */ |
|
34 // } |
|
35 | }, |
|
36 | on_edit_click: function(opstr) { |
|
37 | var size = (typeof this.key_pos_elt !== 'undefined') ? this.key_pos_elt.getBBox() : undefined |
|
38 | edit_value("«path/@value»", "«path/@type»", this, this.last_val, size); |
|
39 | }, |
|
40 |
61 |
41 | edit_callback: function(new_val) { |
|
42 | this.apply_hmi_value(0, new_val); |
|
43 // if "$have_value"{ |
|
44 // | this.value_elt.textContent = String(new_val); |
|
45 // /* TODO gray out value until refreshed */ |
|
46 // } |
|
47 | }, |
62 | }, |
48 } |
63 } |