svghmi/widget_button.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 03 Aug 2020 16:32:23 +0200
branchsvghmi
changeset 3000 a9a45977bac0
parent 2976 99c4521bb844
child 3004 705e34c6fe93
permissions -rw-r--r--
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     1
// widget_button.ysl2
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     3
template "widget[@type='Button']", mode="widget_defs" {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     4
    param "hmi_element";
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     5
    optional_labels("active inactive");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     6
    | frequency: 5,
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     7
    | on_mouse_down: function(evt) {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     8
    |     if (this.active_style && this.inactive_style) {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
     9
    |         this.active_elt.setAttribute("style", this.active_style);
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    10
    |         this.inactive_elt.setAttribute("style", "display:none");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    11
    |     }
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    12
    |     apply_hmi_value(this.get_idx(0), 1);
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    13
    | },
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    14
    | on_mouse_up: function(evt) {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    15
    |     if (this.active_style && this.inactive_style) {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    16
    |         this.active_elt.setAttribute("style", "display:none");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    17
    |         this.inactive_elt.setAttribute("style", this.inactive_style);
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    18
    |     }
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    19
    |     apply_hmi_value(this.get_idx(0), 0);
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    20
    | },
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    21
    | active_style: undefined,
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    22
    | inactive_style: undefined,
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    23
    | init: function() {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    24
    |   this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    25
    |   this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    26
    |   if (this.active_style && this.inactive_style) {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    27
    |       this.active_elt.setAttribute("style", "display:none");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    28
    |       this.inactive_elt.setAttribute("style", this.inactive_style);
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    29
    |   }
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    30
    |   this.element.setAttribute("onmousedown", "hmi_widgets['«$hmi_element/@id»'].on_mouse_down(evt)");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    31
    |   this.element.setAttribute("onmouseup", "hmi_widgets['«$hmi_element/@id»'].on_mouse_up(evt)");
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    32
    | },
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    33
}