svghmi/widget_display.ysl2
branchsvghmi
changeset 3142 2637bb6a6bb0
parent 3065 c369a742443d
child 3204 856f4698a0a8
equal deleted inserted replaced
3141:6d4c1e6560ac 3142:2637bb6a6bb0
     5     ||
     5     ||
     6     class DisplayWidget extends Widget{
     6     class DisplayWidget extends Widget{
     7         frequency = 5;
     7         frequency = 5;
     8         dispatch(value, oldval, index) {
     8         dispatch(value, oldval, index) {
     9             this.fields[index] = value;    
     9             this.fields[index] = value;    
    10             this.element.textContent = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
    10             this.request_animate();
    11         }
    11         }
    12     }
    12     }
    13     ||
    13     ||
    14 
    14 
    15 template "widget[@type='Display']", mode="widget_defs" {
    15 template "widget[@type='Display']", mode="widget_defs" {
    16     param "hmi_element";
    16     param "hmi_element";
    17     if "$hmi_element[not(self::svg:text)]"
    17 
    18         error > Display Widget id="«$hmi_element/@id»" is not a svg::text element
    18     const "format" optional_labels("format");
       
    19     const "has_format","string-length($format)>0";
       
    20     value "$format";
       
    21 
       
    22     if "$hmi_element[not(self::svg:text)] and not($has_format)"
       
    23         error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format"
    19 
    24 
    20     const "field_initializer" foreach "path" {
    25     const "field_initializer" foreach "path" {
    21         choose{
    26         choose{
    22             when "@type='HMI_STRING'" > ""
    27             when "@type='HMI_STRING'" > ""
    23             otherwise > 0
    28             otherwise > 0
    24         }
    29         }
    25         if "position()!=last()" > ,
    30         if "position()!=last()" > ,
    26     }
    31     }
    27     |     fields: [«$field_initializer»],
    32     |     fields: [«$field_initializer»],
       
    33     |     animate: function(){
       
    34     choose {
       
    35         when "$has_format" {
       
    36     |       if(this.format_elt.getAttribute("lang")) {
       
    37     |           this.format = svg_text_to_multiline(this.format_elt);
       
    38     |           this.format_elt.removeAttribute("lang");
       
    39     |       }
       
    40     |       let str = vsprintf(this.format,this.fields);
       
    41     |       multiline_to_svg_text(this.format_elt, str);
       
    42         }
       
    43         otherwise {
       
    44     |       let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
       
    45     |       multiline_to_svg_text(this.element, str);
       
    46         }
       
    47     }
       
    48     |     },
       
    49     |     
       
    50     if "$has_format" {
       
    51     |     init: function() {
       
    52     |       this.format = svg_text_to_multiline(this.format_elt);
       
    53     |     },
       
    54     }
    28 }
    55 }
    29 
    56 
    30 emit "preamble:display"
    57 emit "preamble:display"
    31 ||
    58 ||
    32 /* https://github.com/alexei/sprintf.js/blob/master/src/sprintf.js */
    59 /* https://github.com/alexei/sprintf.js/blob/master/src/sprintf.js */