svghmi/widget_button.ysl2
author usveticic
Tue, 18 Aug 2020 11:42:28 +0200
branchsvghmi
changeset 3045 f6d428330e04
parent 3024 0a9f6f29b7dd
child 3037 da51baea69cb
child 3056 827bf284feec
permissions -rw-r--r--
All widgets reworked to use widget class and animate function if needed
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
3024
Edouard Tisserant
parents: 3018
diff changeset
     3
template "widget[@type='Button']", mode="widget_class"{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     4
    ||
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     5
    class ButtonWidget extends Widget{
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     6
        frequency = 5;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     7
        state = 0;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     8
        active_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     9
        inactive_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    10
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    11
         on_mouse_down(evt) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    12
             if (this.active_style && this.inactive_style) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    13
                 this.active_elt.setAttribute("style", this.active_style);
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    14
                 this.inactive_elt.setAttribute("style", "display:none");
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    15
             }
3018
Edouard Tisserant
parents: 3009
diff changeset
    16
             this.apply_hmi_value(0, 1);
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    17
         }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    18
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    19
         on_mouse_up(evt) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    20
             if (this.active_style && this.inactive_style) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    21
                 this.active_elt.setAttribute("style", "display:none");
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    22
                 this.inactive_elt.setAttribute("style", this.inactive_style);
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    23
             }
3018
Edouard Tisserant
parents: 3009
diff changeset
    24
             this.apply_hmi_value(0, 0);
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    25
         }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    26
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    27
         init() {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    28
            this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    29
            this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    30
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    31
            if (this.active_style && this.inactive_style) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    32
                this.active_elt.setAttribute("style", "display:none");
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    33
                this.inactive_elt.setAttribute("style", this.inactive_style);
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    34
            }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    35
3018
Edouard Tisserant
parents: 3009
diff changeset
    36
            this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)");
Edouard Tisserant
parents: 3009
diff changeset
    37
            this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)");
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    38
         }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    39
    }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    40
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    41
}
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    42
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    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
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    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
}