author | Edouard Tisserant |
Tue, 01 Sep 2020 11:15:48 +0200 | |
branch | svghmi |
changeset 3050 | f9d494d11339 |
parent 3039 | 5ca37a7b89e2 |
child 3058 | 6ea4b7e1a9ed |
permissions | -rw-r--r-- |
2944 | 1 |
// widget_button.ysl2 |
2 |
||
3024 | 3 |
template "widget[@type='Button']", mode="widget_class"{ |
3009 | 4 |
|| |
5 |
class ButtonWidget extends Widget{ |
|
6 |
frequency = 5; |
|
7 |
state = 0; |
|
8 |
active_style = undefined; |
|
9 |
inactive_style = undefined; |
|
10 |
||
3039 | 11 |
// TODO decouple update of DOM from event (i.e use animate()) |
3009 | 12 |
|
13 |
||
3039 | 14 |
// TODO State of the button should distinguish UI feedbak from current PLC value |
3009 | 15 |
|
3039 | 16 |
on_mouse_down(evt) { |
17 |
if (this.active_style && this.inactive_style) { |
|
18 |
this.active_elt.setAttribute("style", this.active_style); |
|
19 |
this.inactive_elt.setAttribute("style", "display:none"); |
|
20 |
} |
|
21 |
this.apply_hmi_value(0, 1); |
|
22 |
// TODO inhibit all mouse/touch events except mouse up (in other word grab cursor) |
|
23 |
} |
|
24 |
||
25 |
on_mouse_up(evt) { |
|
3009 | 26 |
if (this.active_style && this.inactive_style) { |
27 |
this.active_elt.setAttribute("style", "display:none"); |
|
28 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
29 |
} |
|
3039 | 30 |
this.apply_hmi_value(0, 0); |
31 |
// TODO release inhibited events |
|
32 |
} |
|
3009 | 33 |
|
3039 | 34 |
init() { |
35 |
// TODO : move to widget_defs so that we can have generated string literals directly |
|
36 |
this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
|
37 |
this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
|
38 |
||
39 |
if (this.active_style && this.inactive_style) { |
|
40 |
this.active_elt.setAttribute("style", "display:none"); |
|
41 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
42 |
} |
|
43 |
||
44 |
this.element.setAttribute("onmousedown", "hmi_widgets[\""+this.element_id+"\"].on_mouse_down(evt)"); |
|
45 |
this.element.setAttribute("onmouseup", "hmi_widgets[\""+this.element_id+"\"].on_mouse_up(evt)"); |
|
46 |
} |
|
3009 | 47 |
} |
48 |
|| |
|
3024 | 49 |
} |
3009 | 50 |
|
51 |
||
2976
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
52 |
template "widget[@type='Button']", mode="widget_defs" { |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
53 |
param "hmi_element"; |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
54 |
optional_labels("active inactive"); |
3009 | 55 |
|, |
3000
a9a45977bac0
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2976
diff
changeset
|
56 |
} |