author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 02 May 2021 23:01:08 +0200 | |
branch | svghmi |
changeset 3232 | 7bdb766c2a4d |
parent 3219 | cc0ecc5e918f |
child 3241 | fe945f1f48b7 |
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 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3219
diff
changeset
|
4 |
widget_class("ToggleButton") { |
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 |
frequency = 5; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
7 |
state = 0; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
8 |
active_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
9 |
inactive_style = undefined; |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
10 |
|
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
11 |
dispatch(value) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
12 |
this.state = value; |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
13 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
14 |
this.request_animate(); |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
15 |
} |
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 |
on_click(evt) { |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
18 |
//toggle state and apply |
3219 | 19 |
this.state = this.state ? false : true; |
3018 | 20 |
this.apply_hmi_value(0, this.state); |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
21 |
|
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
22 |
//redraw toggle button |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
23 |
this.request_animate(); |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
24 |
} |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
25 |
|
3219 | 26 |
activate(val) { |
27 |
let [active, inactive] = val ? ["none",""] : ["", "none"]; |
|
28 |
if (this.active_elt) |
|
29 |
this.active_elt.style.display = active; |
|
30 |
if (this.inactive_elt) |
|
31 |
this.inactive_elt.style.display = inactive; |
|
32 |
} |
|
33 |
||
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
34 |
animate(){ |
3219 | 35 |
// redraw toggle button on screen refresh |
36 |
this.activate(this.state); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
37 |
} |
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 |
init() { |
3219 | 40 |
this.activate(false); |
41 |
this.element.onclick = (evt) => this.on_click(evt); |
|
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
42 |
} |
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
43 |
|| |
3024 | 44 |
} |
3011
601c6dbc1da7
Reworked togglebutton widget to extand class widget
usveticic
parents:
3004
diff
changeset
|
45 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3219
diff
changeset
|
46 |
widget_defs("ToggleButton") { |
2977 | 47 |
param "hmi_element"; |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3056
diff
changeset
|
48 |
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
|
49 |
} |