svghmi/widget_input.ysl2
author Edouard Tisserant
Mon, 15 Mar 2021 11:25:24 +0100
branchsvghmi
changeset 3188 c173452bf894
parent 3155 99ce78ddd353
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.
// widget_input.ysl2

template "widget[@type='Input']", mode="widget_class"{
||
    class InputWidget extends Widget{
         on_op_click(opstr) {
             this.change_hmi_value(0, opstr);
         }
         edit_callback(new_val) {
             this.apply_hmi_value(0, new_val);
         }

         is_inhibited = false;
         alert(msg){
             this.is_inhibited = true;
             this.display = msg;
             setTimeout(() => this.stopalert(), 1000);
             this.request_animate();
         }

         stopalert(){
             this.is_inhibited = false;
             this.display = this.last_value;
             this.request_animate();
         }

         overshot(new_val, max) {
             this.alert("max");
         }

         undershot(new_val, min) {
             this.alert("min");
         }


    }
||
}

template "widget[@type='Input']", mode="widget_defs" {
    param "hmi_element";

    const "value_elt" optional_labels("value");
    const "have_value","string-length($value_elt)>0";
    value "$value_elt";

    const "edit_elt" optional_labels("edit");
    const "have_edit","string-length($edit_elt)>0";
    value "$edit_elt";

    if "$have_value"
    |     frequency: 5,

    |     dispatch: function(value) {


    if "$have_value or $have_edit" {
        choose{
            when "count(arg) = 1" {
    |         this.last_value = vsprintf("«arg[1]/@value»", [value]);
            }
            otherwise {
    |         this.last_value = value;
            }
        }
    |         if(!this.is_inhibited){
    |             this.display = this.last_value;
    if "$have_value" {
    |             this.request_animate();
    }
    |         }
    }
    |     },

    if "$have_value" {
    |     animate: function(){
    |         this.value_elt.textContent = String(this.display);
    |     },
    }

    |     init: function() {

    if "$have_edit" {
    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_value);
        if "$have_value" {
    |         this.value_elt.style.pointerEvents = "none";
        }
    }

    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
    |         id("«@id»").onclick = () => this.on_op_click("«func:escape_quotes(@inkscape:label)»");
    }

    |     },
}