# HG changeset patch
# User Edouard Tisserant
# Date 1655709596 -7200
# Node ID c663d1f9f03bc7c8c0f07b6881333a020c38a7a2
# Parent dacf329abdd93baf1b29fc9a34038c6d31eb6b32
SVGHMI: fix Switch widget so that order of choices elements is preserved across detaching and re-attaching.
diff -r dacf329abdd9 -r c663d1f9f03b svghmi/widget_switch.ysl2
--- a/svghmi/widget_switch.ysl2 Wed Jun 15 11:46:48 2022 +0200
+++ b/svghmi/widget_switch.ysl2 Mon Jun 20 09:19:56 2022 +0200
@@ -43,7 +43,7 @@
}
} else {
if(choice.parent != undefined){
- choice.parent.appendChild(choice.elt);
+ choice.parent.insertBefore(choice.elt,choice.sibling);
choice.parent = undefined;
}
}
@@ -60,11 +60,21 @@
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 "choices", "$accepted[regexp:test(@inkscape:label,$regex)]";
+ foreach "$choices" {
const "literal", "regexp:match(@inkscape:label,$regex)[2]";
+ const "sibling", "following-sibling::*[not(@id = $choices/@id)][position()=1]";
| {
| elt:id("«@id»"),
| parent:undefined,
+ choose {
+ when "count($sibling)=0" {
+ | sibling:null,
+ }
+ otherwise {
+ | sibling:id("«$sibling/@id»"),
+ }
+ }
| value:«$literal»
| }`if "position()!=last()" > ,`
}
diff -r dacf329abdd9 -r c663d1f9f03b tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg Wed Jun 15 11:46:48 2022 +0200
+++ b/tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg Mon Jun 20 09:19:56 2022 +0200
@@ -125,12 +125,12 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:document-units="px"
- inkscape:current-layer="hmi0"
+ inkscape:current-layer="g5053"
showgrid="false"
units="px"
- inkscape:zoom="0.20046201"
- inkscape:cx="1401.1703"
- inkscape:cy="-1495.7332"
+ inkscape:zoom="0.80184804"
+ inkscape:cx="784.66046"
+ inkscape:cy="-449.34319"
inkscape:window-width="1600"
inkscape:window-height="836"
inkscape:window-x="0"
@@ -2244,6 +2244,42 @@
inkscape:label="HMI:Switch@/PUMP0/BOOLOUT"
transform="translate(43.983597,40.477445)">
+
+
+
+
+
+
+
+
@@ -2278,6 +2314,15 @@
id="path3461"
inkscape:connector-curvature="0" />
+