svghmi/widget_switch.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 02 Apr 2021 21:16:18 +0200
branchsvghmi
changeset 3221 3d307ad803ea
parent 3220 ec365ef396b1
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
// widget_switch.ysl2

template "widget[@type='Switch']", mode="widget_class"
    ||
    class SwitchWidget extends Widget{
        frequency = 5;
        dispatch(value) {
            for(let choice of this.choices){
                if(value != choice.value){
                    choice.elt.setAttribute("style", "display:none");
                } else {
                    choice.elt.setAttribute("style", choice.style);
                }
            }
        }
    }
    ||

template "widget[@type='Switch']", mode="widget_defs" {
    param "hmi_element";
    |     choices: [
    const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;

    const "subelts", "$result_widgets[@id = $hmi_element/@id]//*";
    const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
    const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]";

    foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
        const "literal", "regexp:match(@inkscape:label,$regex)[2]";
    |         {
    |             elt:id("«@id»"),
    |             style:"«@style»",
    |             value:«$literal»
    |         }`if "position()!=last()" > ,`
    }
    |     ],
}