svghmi/widget_keypad.ysl2
author Edouard Tisserant
Thu, 04 Jun 2020 11:14:21 +0200
branchsvghmi
changeset 2980 2a21d6060d64
parent 2943 304e88bae115
child 3010 893cc309f5e2
permissions -rw-r--r--
SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons.
In most cases jump buttons do not really subscribe to pointed HMI variable, path is given as a relative page jump path. When widget.unsubscribable is set to true, no subscription is made on page switch, but still offset is updated.
This fixes bug happening on relative jump buttons without "disabled" element where offset did not change on relative page switch.
// widget_keypad.ysl2

emit "declarations:keypad" {
    |
    | var keypads = {
    foreach "$keypads_descs"{
        const "keypad_id","@id";
        foreach "arg"{
            const "g", "$geometry[@Id = $keypad_id]";
    |     "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»],
        }
    }
    | }
}

template "widget[@type='Keypad']", mode="widget_defs" {
    param "hmi_element";
    labels("Esc Enter BackSpace Keys Info Value");
    optional_labels("Sign Space NumDot");
    activable_labels("CapsLock Shift");
    |     init: function() {
    foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" {
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')");
    }
    foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" {
    |         if(this.«.»_elt)
    |             this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()");
    }
    |     },
    |     on_key_click: function(symbols) {
    |         var syms = symbols.split(" ");
    |         this.shift |= this.caps;
    |         this.editstr += syms[this.shift?syms.length-1:0];
    |         this.shift = false;
    |         this.update();
    |     },
    |     on_Esc_click: function() {
    |         end_modal.call(this);
    |     },
    |     on_Enter_click: function() {
    |         end_modal.call(this);
    |         callback_obj = this.result_callback_obj;
    |         callback_obj.edit_callback(this.editstr);
    |     },
    |     on_BackSpace_click: function() {
    |         this.editstr = this.editstr.slice(0,this.editstr.length-1);
    |         this.update();
    |     },
    |     on_Sign_click: function() {
    |         if(this.editstr[0] == "-")
    |             this.editstr = this.editstr.slice(1,this.editstr.length);
    |         else
    |             this.editstr = "-" + this.editstr;
    |         this.update();
    |     },
    |     on_NumDot_click: function() {
    |         if(this.editstr.indexOf(".") == "-1"){
    |             this.editstr += ".";
    |             this.update();
    |         }
    |     },
    |     on_Space_click: function() {
    |         this.editstr += " ";
    |         this.update();
    |     },
    |     caps: false,
    |     _caps: undefined,
    |     on_CapsLock_click: function() {
    |         this.caps = !this.caps;
    |         this.update();
    |     },
    |     shift: false,
    |     _shift: undefined,
    |     on_Shift_click: function() {
    |         this.shift = !this.shift;
    |         this.caps = false;
    |         this.update();
    |     },
    const "g", "$geometry[@Id = $hmi_element/@id]"; 
    |     coordinates: [«$g/@x», «$g/@y»],
    |     editstr: "",
    |     _editstr: undefined,
    |     result_callback_obj: undefined,
    |     start_edit: function(info, valuetype, callback_obj, initial) {
    |         show_modal.call(this);
    |         this.editstr = initial;
    |         this.result_callback_obj = callback_obj;
    |         this.Info_elt.textContent = info;
    |         this.shift = false;
    |         this.caps = false;
    |         this.update();
    |     },
    |     update: function() {
    |         if(this.editstr != this._editstr){
    |             this._editstr = this.editstr;
    |             this.Value_elt.textContent = this.editstr;
    |         }
    |         if(this.shift != this._shift){
    |             this._shift = this.shift;
    |             (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub);
    |         }
    |         if(this.caps != this._caps){
    |             this._caps = this.caps;
    |             (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub);
    |         }
    |     },
}