svghmi/widget_keypad.ysl2
author usveticic
Tue, 18 Aug 2020 11:42:28 +0200
branchsvghmi
changeset 3045 f6d428330e04
parent 3010 893cc309f5e2
child 3047 c113904f0e62
permissions -rw-r--r--
All widgets reworked to use widget class and animate function if needed
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
     1
// widget_keypad.ysl2
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
     2
2943
304e88bae115 SVGHMI: added more meaningful namespaces to emit javascript code from.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
     3
emit "declarations:keypad" {
2941
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     4
    |
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     5
    | var keypads = {
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     6
    foreach "$keypads_descs"{
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     7
        const "keypad_id","@id";
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     8
        foreach "arg"{
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     9
            const "g", "$geometry[@Id = $keypad_id]";
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    10
    |     "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»],
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    11
        }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    12
    }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    13
    | }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    14
}
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    15
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    16
template "widget[@type='Keypad']", mode="widget_class"
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    17
    ||
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    18
    class KeypadWidget extends Widget{
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    19
         moving = undefined;
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    20
         click = undefined;
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    21
         offset = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    22
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    23
         on_position_click(evt) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    24
             this.moving = true;
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    25
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    26
             // chatch window events
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    27
             window.addEventListener("touchmove", this.bound_on_drag, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    28
             window.addEventListener("mousemove", this.bound_on_drag, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    29
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    30
             window.addEventListener("mouseup", this.bound_on_release, true)
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    31
             window.addEventListener("touchend", this.bound_on_release, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    32
             window.addEventListener("touchcancel", this.bound_on_release, true);
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    33
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    34
             // get click position offset from widget x,y and save it to variable
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    35
             var keypad_borders = this.position_elt.getBoundingClientRect();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    36
             var clickX = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    37
             var clickY = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    38
             if (evt.type == "touchstart"){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    39
                 clickX = Math.ceil(evt.touches[0].clientX);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    40
                 clickY = Math.ceil(evt.touches[0].clientY);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    41
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    42
             else{
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    43
                 clickX = evt.pageX;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    44
                 clickY = evt.pageY;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    45
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    46
             this.offset=[clickX-keypad_borders.left,clickY-keypad_borders.top]
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    47
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    48
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    49
         on_release(evt) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    50
            //relase binds
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    51
            window.removeEventListener("touchmove", this.bound_on_drag, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    52
            window.removeEventListener("mousemove", this.bound_on_drag, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    53
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    54
            window.removeEventListener("mouseup", this.bound_on_release, true)
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    55
            window.removeEventListener("touchend", this.bound_on_release, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    56
            window.removeEventListener("touchcancel", this.bound_on_release, true);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    57
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    58
            if(this.moving)
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    59
                this.moving = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    60
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    61
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    62
         on_drag(evt) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    63
             if(this.moving)
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    64
                //get mouse coordinates
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    65
                var clickX = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    66
                var clickY = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    67
                if (evt.type == "touchmove"){
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    68
                    clickX = Math.ceil(evt.touches[0].clientX);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    69
                    clickY = Math.ceil(evt.touches[0].clientY);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    70
                }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    71
                else{
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    72
                    clickX = evt.pageX;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    73
                    clickY = evt.pageY;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    74
                }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    75
                this.click = [clickX,clickY]
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    76
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    77
                //requeset redraw
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    78
                this.request_animate();
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    79
         }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    80
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    81
         animate(){
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    82
            //get keyboard pos in html
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    83
            let [eltid, tmpgrp] = current_modal;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    84
            let [xcoord,ycoord] = this.coordinates;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    85
            let [clickX,clickY] = this.click;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    86
            let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    87
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    88
            //translate keyboard position
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    89
            let mouseX = ((clickX-this.offset[0])/window.innerWidth)*svgWidth;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    90
            let mouseY = ((clickY-this.offset[1])/window.innerHeight)*svgHeight;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
    91
            tmpgrp.setAttribute("transform","translate("+String(xdest-xcoord+mouseX)+","+String(ydest-ycoord+mouseY)+")");
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    92
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    93
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    94
         on_key_click(symbols) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    95
             var syms = symbols.split(" ");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    96
             this.shift |= this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    97
             this.editstr += syms[this.shift?syms.length-1:0];
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    98
             this.shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    99
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   100
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   101
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   102
         on_Esc_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   103
             end_modal.call(this);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   104
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   105
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   106
         on_Enter_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   107
             end_modal.call(this);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   108
             let callback_obj = this.result_callback_obj;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   109
             callback_obj.edit_callback(this.editstr);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   110
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   111
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   112
         on_BackSpace_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   113
             this.editstr = this.editstr.slice(0,this.editstr.length-1);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   114
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   115
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   116
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   117
         on_Sign_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   118
             if(this.editstr[0] == "-")
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   119
                 this.editstr = this.editstr.slice(1,this.editstr.length);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   120
             else
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   121
                 this.editstr = "-" + this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   122
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   123
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   124
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   125
         on_NumDot_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   126
             if(this.editstr.indexOf(".") == "-1"){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   127
                 this.editstr += ".";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   128
                 this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   129
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   130
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   131
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   132
         on_Space_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   133
             this.editstr += " ";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   134
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   135
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   136
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   137
         caps = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   138
         _caps = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   139
         on_CapsLock_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   140
             this.caps = !this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   141
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   142
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   143
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   144
         shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   145
         _shift = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   146
         on_Shift_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   147
             this.shift = !this.shift;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   148
             this.caps = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   149
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   150
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   151
         editstr = "";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   152
         _editstr = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   153
         result_callback_obj = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   154
         start_edit(info, valuetype, callback_obj, initial,size) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   155
             show_modal.call(this,size);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   156
             this.editstr = initial;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   157
             this.result_callback_obj = callback_obj;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   158
             this.Info_elt.textContent = info;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   159
             this.shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   160
             this.caps = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   161
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   162
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   163
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   164
         update() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   165
             if(this.editstr != this._editstr){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   166
                 this._editstr = this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   167
                 this.Value_elt.textContent = this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   168
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   169
             if(this.shift != this._shift){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   170
                 this._shift = this.shift;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   171
                 (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   172
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   173
             if(this.caps != this._caps){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   174
                 this._caps = this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   175
                 (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   176
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   177
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   178
    }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   179
    ||
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   180
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
   181
template "widget[@type='Keypad']", mode="widget_defs" {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   182
    param "hmi_element";
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   183
    labels("Esc Enter BackSpace Keys Info Value");
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   184
    optional_labels("Sign Space NumDot position");
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2919
diff changeset
   185
    activable_labels("CapsLock Shift");
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2908
diff changeset
   186
    |     init: function() {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   187
    foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" {
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   188
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')");
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   189
    }
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2919
diff changeset
   190
    foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   191
    |         if(this.«.»_elt)
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   192
    |             this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()");
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   193
    }
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   194
    |         if(this.position_elt){
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
   195
    |            this.bound_on_release = this.on_release.bind(this);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
   196
    |            this.bound_on_drag = this.on_drag.bind(this);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 3010
diff changeset
   197
    |
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   198
    |            this.position_elt.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   199
    |            this.position_elt.setAttribute("ontouchstart", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   200
    |        }
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   201
    |     },
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   202
    |
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   203
    const "g", "$geometry[@Id = $hmi_element/@id]"; 
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   204
    |     coordinates: [«$g/@x», «$g/@y»],
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
   205
}