svghmi/widget_foreach.ysl2
branchsvghmi
changeset 2893 d57a12b8f5db
parent 2892 27dd409fba1d
child 2894 4cf9ad35e6d0
equal deleted inserted replaced
2892:27dd409fba1d 2893:d57a12b8f5db
     4     const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
     4     const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
     5     |     frequency: 2,
     5     |     frequency: 2,
     6     |     dispatch: function(value) {
     6     |     dispatch: function(value) {
     7     |                     // do something
     7     |                     // do something
     8     |     },
     8     |     },
       
     9     |     index_pool: [
       
    10     |     ],
       
    11     |     buttons: [
       
    12     const "class","arg[1]/@value";
       
    13     const "prefix","concat($class,':')";
       
    14     const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
       
    15     foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
       
    16     |         ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
       
    17     }
       
    18     |     ],
     9     |     init: function() {
    19     |     init: function() {
    10     foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
    20     |         /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
    11     |         id("«@id»").addEventListener(
       
    12     |             "click", 
       
    13     |             evt => {let new_val = "«func:escape_quotes(@inkscape:label)»");
       
    14     |                     // do something with new_val
       
    15     |                    });
       
    16     }
       
    17     |     },
    21     |     },
    18 
    22 
    19     |     widgets: [
    23     |     items: [
    20     const "labels_regex","concat('^',arg[1]/@value,':[0-9]+')";
    24     const "base_path","path/@value";
    21     foreach "$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]" {
    25     const "items_regex","concat('^',$prefix,'[0-9]+')";
    22     |       [ /* «@inkscape:label» */
    26     const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
    23         const "elt",".";
    27     foreach "$unordered_items" {
    24         //foreach "$hmi_elements[ancestor::svg:*/@id = $_id]" {
    28         const "elt_label","concat($prefix, string(position()))"; 
    25         foreach "func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    29         const "elt","$unordered_items[@inkscape:label = $elt_label]";
       
    30         
       
    31     |   /* `apply "func:get_hmi_tree_elt($base_path)", mode="testtree";` */
       
    32     |       [ /* «$elt_label» */
       
    33         if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
       
    34         foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    26     |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    35     |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    27         }
    36         }
    28     |       ]`if "position()!=last()" > ,`
    37     |       ]`if "position()!=last()" > ,`
    29     }
    38     }
    30     |     ],
    39     |     ],