svghmi/widget_input.ysl2
author Edouard Tisserant
Wed, 13 Jan 2021 10:28:09 +0100
branchsvghmi
changeset 3109 6c39d718e8cb
parent 3101 4cbf024a6640
child 3118 e704b0487515
permissions -rw-r--r--
Removed harmful assert in ProcessLogger.

ProcessLogger was having an assert in constructor when missing logger, leading to systematic exception when testing options accepted by compiler. This exception was silenced in ProjectController, and then MatIEC was always called without options.
// 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);
         }

         overshot(new_val, max) {
             this.last_display = "max: "+max;
             this.request_animate();
         }

         undershot(new_val, min) {
             this.last_display = "min: "+min;
             this.request_animate();
         }


    }
||
}

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

    const "key_pos_elt" optional_labels("key_pos");
    value "$key_pos_elt";

    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_edit"
    |         this.last_val = value;

    if "$have_value" {
    |         this.last_display = value;
    |         this.request_animate();
    }
    |     },

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

    |     init: function() {

    if "$have_edit" {
    |         this.edit_elt.onclick = () => edit_value(
    |             "«path/@value»", "«path/@type»",
    |             this, this.last_val, 
        choose {
            when "string-length($key_pos_elt)>0"
    |             this.key_pos_elt.getBBox()
            otherwise
    |             undefined
        }
    |         );
    }

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

    |     },
}