author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 20 Oct 2020 00:23:52 +0200 | |
branch | svghmi |
changeset 3063 | 466c3df67835 |
parent 3058 | 6ea4b7e1a9ed |
child 3059 | e0db3f6a5f39 |
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; |
|
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
8 |
plc_lock = false; |
3009 | 9 |
active_style = undefined; |
10 |
inactive_style = undefined; |
|
11 |
||
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
12 |
dispatch(value) { |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
13 |
if(value){ |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
14 |
this.button_release(); |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
15 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
16 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
17 |
|
3009 | 18 |
on_mouse_down(evt) { |
19 |
if (this.active_style && this.inactive_style) { |
|
20 |
this.active_elt.setAttribute("style", this.active_style); |
|
21 |
this.inactive_elt.setAttribute("style", "display:none"); |
|
22 |
} |
|
3018 | 23 |
this.apply_hmi_value(0, 1); |
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
24 |
this.plc_lock = false; |
3009 | 25 |
} |
26 |
||
27 |
on_mouse_up(evt) { |
|
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
28 |
this.button_release(); |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
29 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
30 |
|
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
31 |
button_release(){ |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
32 |
if(!this.plc_lock){ |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
33 |
this.plc_lock = true; |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
34 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
35 |
else{ |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
36 |
if (this.active_style && this.inactive_style) { |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
37 |
this.active_elt.setAttribute("style", "display:none"); |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
38 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
39 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
40 |
this.apply_hmi_value(0, 0); |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
41 |
} |
3009 | 42 |
} |
43 |
||
44 |
init() { |
|
45 |
this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
|
46 |
this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
|
47 |
||
48 |
if (this.active_style && this.inactive_style) { |
|
49 |
this.active_elt.setAttribute("style", "display:none"); |
|
50 |
this.inactive_elt.setAttribute("style", this.inactive_style); |
|
51 |
} |
|
52 |
||
3018 | 53 |
this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)"); |
54 |
this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)"); |
|
3009 | 55 |
} |
56 |
} |
|
57 |
|| |
|
3024 | 58 |
} |
3009 | 59 |
|
60 |
||
2976
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
61 |
template "widget[@type='Button']", mode="widget_defs" { |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
62 |
param "hmi_element"; |
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
63 |
optional_labels("active inactive"); |
3009 | 64 |
|, |
3000
a9a45977bac0
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2976
diff
changeset
|
65 |
} |