svghmi/widget_tooglebutton.ysl2
branchsvghmi
changeset 3219 cc0ecc5e918f
parent 3059 e0db3f6a5f39
child 3232 7bdb766c2a4d
equal deleted inserted replaced
3218:76f1cd1291f4 3219:cc0ecc5e918f
    15             this.request_animate();
    15             this.request_animate();
    16         }
    16         }
    17 
    17 
    18         on_click(evt) {
    18         on_click(evt) {
    19             //toggle state and apply
    19             //toggle state and apply
    20             if (this.state) {
    20             this.state = this.state ? false : true;
    21                 this.state = 0;
       
    22             } else {
       
    23                 this.state = 1;
       
    24             }
       
    25             this.apply_hmi_value(0, this.state);
    21             this.apply_hmi_value(0, this.state);
    26 
    22 
    27             //redraw toggle button
    23             //redraw toggle button
    28             this.request_animate();
    24             this.request_animate();
    29         }
    25         }
    30 
    26 
       
    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 
    31         animate(){
    35         animate(){
    32            // redraw toggle button on screen refresh
    36             // redraw toggle button on screen refresh
    33            if (this.state) {
    37             this.activate(this.state);
    34                this.active_elt.setAttribute("style", this.active_style);
       
    35                this.inactive_elt.setAttribute("style", "display:none");
       
    36            } else {
       
    37                this.inactive_elt.setAttribute("style", this.inactive_style);
       
    38                this.active_elt.setAttribute("style", "display:none");
       
    39            }
       
    40         }
    38         }
    41 
    39 
    42         init() {
    40         init() {
    43             this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
    41             this.activate(false);
    44             this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
    42             this.element.onclick = (evt) => this.on_click(evt);
    45 
       
    46             if (this.active_style && this.inactive_style) {
       
    47                 this.active_elt.setAttribute("style", "display:none");
       
    48                 this.inactive_elt.setAttribute("style", this.inactive_style);
       
    49             }
       
    50 
       
    51             this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
       
    52         }
    43         }
    53     }
    44     }
    54     ||
    45     ||
    55 }
    46 }
    56 
    47 
    57 template "widget[@type='ToggleButton']", mode="widget_defs" {
    48 template "widget[@type='ToggleButton']", mode="widget_defs" {
    58     param "hmi_element";
    49     param "hmi_element";
    59     optional_labels("active inactive");
    50     optional_labels("active inactive");
    60     |,
       
    61 }
    51 }