svghmi/widget_button.ysl2
author Edouard Tisserant
Wed, 02 Dec 2020 14:31:57 +0100
branchsvghmi
changeset 3082 20a5eb6a02e6
parent 3062 9ec338a99a18
child 3085 6b1b23971960
permissions -rw-r--r--
SVGHMI: prevent unwnted context menu and pinch zoom
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;
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     7
        state_plc = 0;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     8
        state_hmi = 0;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
     9
        plc_lock = false;
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    10
        active_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    11
        inactive_style = undefined;
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    12
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    13
        dispatch(value) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    14
            this.state_plc = value;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    15
            if(this.plc_lock){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    16
                if(this.state_plc == 1){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    17
                    this.apply_hmi_value(0, 0);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    18
                    this.plc_lock = false;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    19
                }
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    20
            }
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    21
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    22
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    23
            this.state_hmi = this.state_plc;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    24
            this.request_animate();
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    25
        }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    26
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    27
        animate(){
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    28
            if (this.active_style && this.inactive_style) {
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    29
               // redraw button on screen refresh
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    30
               if (this.state_hmi) {
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    31
                   this.active_elt.setAttribute("style", this.active_style);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    32
                   this.inactive_elt.setAttribute("style", "display:none");
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    33
               } else {
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    34
                   this.inactive_elt.setAttribute("style", this.inactive_style);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    35
                   this.active_elt.setAttribute("style", "display:none");
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    36
               }
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    37
           }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    38
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    39
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    40
        on_click(evt) {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    41
            //set state and apply if plc is 0
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    42
            this.plc_lock = true;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    43
            if(this.state_plc == 0){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    44
                this.apply_hmi_value(0, 1);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    45
            }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    46
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    47
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    48
        }
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    49
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    50
        on_press(evt) {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    51
            //set graphic
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    52
            this.state_hmi = 1;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    53
            //redraw button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    54
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    55
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    56
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    57
         init() {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    58
            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
    59
            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
    60
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    61
            if (this.active_style && this.inactive_style) {
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    62
                this.active_elt.setAttribute("style", "display:none");
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    63
                this.inactive_elt.setAttribute("style", this.inactive_style);
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    64
            }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    65
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    66
            this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    67
            this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)");
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    68
         }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    69
    }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    70
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    71
}
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    72
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    73
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    74
template "widget[@type='Button']", mode="widget_defs" {
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    75
    param "hmi_element";
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    76
    optional_labels("active inactive");
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    77
    |,
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    78
}