author | Edouard Tisserant |
Thu, 20 Aug 2020 14:12:49 +0200 | |
branch | svghmi |
changeset 3032 | 2f6dfb99d094 |
parent 3024 | 0a9f6f29b7dd |
child 3037 | da51baea69cb |
child 3056 | 827bf284feec |
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 |
||
11 |
on_mouse_down(evt) { |
|
12 |
if (this.active_style && this.inactive_style) { |
|
13 |
this.active_elt.setAttribute("style", this.active_style); |
|
14 |
this.inactive_elt.setAttribute("style", "display:none"); |
|
15 |
} |
|
3018 | 16 |
this.apply_hmi_value(0, 1); |
3009 | 17 |
} |
18 |
||
19 |
on_mouse_up(evt) { |
|
20 |
if (this.active_style && this.inactive_style) { |
|
21 |
this.active_elt.setAttribute("style", "display:none"); |
|
22 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
23 |
} |
|
3018 | 24 |
this.apply_hmi_value(0, 0); |
3009 | 25 |
} |
26 |
||
27 |
init() { |
|
28 |
this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
|
29 |
this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
|
30 |
||
31 |
if (this.active_style && this.inactive_style) { |
|
32 |
this.active_elt.setAttribute("style", "display:none"); |
|
33 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
34 |
} |
|
35 |
||
3018 | 36 |
this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)"); |
37 |
this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)"); |
|
3009 | 38 |
} |
39 |
} |
|
40 |
|| |
|
3024 | 41 |
} |
3009 | 42 |
|
43 |
||
2976
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
44 |
template "widget[@type='Button']", mode="widget_defs" { |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
45 |
param "hmi_element"; |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
46 |
optional_labels("active inactive"); |
3009 | 47 |
|, |
3000
a9a45977bac0
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2976
diff
changeset
|
48 |
} |