svghmi/widget_input.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 18 Dec 2020 15:52:58 +0100
branchsvghmi
changeset 3094 3e184f1e1012
parent 3034 793ce2117258
child 3100 c51f9cf365c6
permissions -rw-r--r--
SVGHMI: almost rewrote Input widget to make it new class based style.
// widget_input.ysl2

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

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.value_elt.textContent = String(value);

    |     },

    |     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)»");
    }

    |     },
}