svghmi/widget_foreach.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 23 Mar 2020 10:16:38 +0100
branchsvghmi
changeset 2892 27dd409fba1d
parent 2891 8927ae8326b2
child 2893 d57a12b8f5db
permissions -rw-r--r--
SVGHMI: ForEach knows its own widgets

template "widget[@type='ForEach']", mode="widget_defs" {
    param "hmi_element";
    const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
    |     frequency: 2,
    |     dispatch: function(value) {
    |                     // do something
    |     },
    |     init: function() {
    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
    |         id("«@id»").addEventListener(
    |             "click", 
    |             evt => {let new_val = "«func:escape_quotes(@inkscape:label)»");
    |                     // do something with new_val
    |                    });
    }
    |     },

    |     widgets: [
    const "labels_regex","concat('^',arg[1]/@value,':[0-9]+')";
    foreach "$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]" {
    |       [ /* «@inkscape:label» */
        const "elt",".";
        //foreach "$hmi_elements[ancestor::svg:*/@id = $_id]" {
        foreach "func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
        }
    |       ]`if "position()!=last()" > ,`
    }
    |     ],
}

template "widget[@type='ForEach']", mode="widget_subscribe"{
    // param "hmi_element";
    |     sub: function(off){
    |         subscribe.call(this,off);
        /* TODO */
    |     },

    |     unsub: function(){
    |         unsubscribe.call(this);
        /* TODO */
    |     },
}