author | Edouard Tisserant |
Mon, 17 May 2021 08:52:38 +0200 | |
branch | svghmi |
changeset 3240 | 5f756332ada1 |
parent 3219 | cc0ecc5e918f |
child 3232 | 7bdb766c2a4d |
permissions | -rw-r--r-- |
2977 | 1 |
// widget_tooglebutton.ysl2 |
2 |
||
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
3 |
|
3024 | 4 |
template "widget[@type='ToggleButton']", mode="widget_class"{ |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
5 |
|| |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
6 |
class ToggleButtonWidget extends Widget{ |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
7 |
frequency = 5; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
8 |
state = 0; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
9 |
active_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
10 |
inactive_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
11 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
12 |
dispatch(value) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
13 |
this.state = value; |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
14 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
15 |
this.request_animate(); |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
16 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
17 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
18 |
on_click(evt) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
19 |
//toggle state and apply |
3219 | 20 |
this.state = this.state ? false : true; |
3018 | 21 |
this.apply_hmi_value(0, this.state); |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
22 |
|
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
23 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
24 |
this.request_animate(); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
25 |
} |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
26 |
|
3219 | 27 |
activate(val) { |
28 |
let [active, inactive] = val ? ["none",""] : ["", "none"]; |
|
29 |
if (this.active_elt) |
|
30 |
this.active_elt.style.display = active; |
|
31 |
if (this.inactive_elt) |
|
32 |
this.inactive_elt.style.display = inactive; |
|
33 |
} |
|
34 |
||
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
35 |
animate(){ |
3219 | 36 |
// redraw toggle button on screen refresh |
37 |
this.activate(this.state); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
38 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
39 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
40 |
init() { |
3219 | 41 |
this.activate(false); |
42 |
this.element.onclick = (evt) => this.on_click(evt); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
43 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
44 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
45 |
|| |
3024 | 46 |
} |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
47 |
|
2977 | 48 |
template "widget[@type='ToggleButton']", mode="widget_defs" { |
49 |
param "hmi_element"; |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
50 |
optional_labels("active inactive"); |
3004
705e34c6fe93
SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2977
diff
changeset
|
51 |
} |