SVGHMI: add support for multiline widget declaration using svg:desc.
authorEdouard Tisserant
Thu, 11 Aug 2022 12:11:35 +0200
changeset 3579 c5070b6973ba
parent 3578 d74eb1be6abe
child 3580 0c96269bf63b
child 3592 b2bdb8b433e0
SVGHMI: add support for multiline widget declaration using svg:desc.

Declaration started in inkscape:label and interupted by a '\' can be continued in the description field.
After an empty line, the rest of the description field is left for description text.
svghmi/hmi_tree.ysl2
svghmi/parse_labels.ysl2
tests/projects/svghmi_scrollbar/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/hmi_tree.ysl2	Tue Aug 02 11:53:37 2022 +0200
+++ b/svghmi/hmi_tree.ysl2	Thu Aug 11 12:11:35 2022 +0200
@@ -121,6 +121,7 @@
     > «$indent» «local-name()» 
     foreach "@*" > «local-name()»="«.»" 
     > \n
+    if "text()" > «text()»\n
     apply "*", mode="testtree" {
         with "indent" value "concat($indent,'>')"
     };
--- a/svghmi/parse_labels.ysl2	Tue Aug 02 11:53:37 2022 +0200
+++ b/svghmi/parse_labels.ysl2	Thu Aug 11 12:11:35 2022 +0200
@@ -15,9 +15,29 @@
 //
 const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([-.\d,]*)$'"!;
 
+const "newline" |
+const "twonewlines", "concat($newline,$newline)";
+
 template "*", mode="parselabel"
 {
-    const "label","@inkscape:label";
+    const "part","@inkscape:label";
+    const "desc", "svg:desc";
+
+    // add svg:desc field if continuation "\" marker is found at the end of label
+    const "len","string-length($part)";
+    const "has_continuation", "substring($part,$len,1)='\\'";
+    const "label" choose{
+        when "$has_continuation" {
+           const "_continuation", "substring-before($desc, $twonewlines)";
+           const "continuation" choose {
+               when "$_continuation" value "$_continuation";
+               otherwise value "$desc";
+           }
+           value "concat(substring($part,1,$len - 1),translate($continuation,$newline,''))";
+        }
+        otherwise value "$part";
+    }
+
     const "id","@id";
 
     const "description", "substring-after($label,'HMI:')";
@@ -100,7 +120,15 @@
                 }
             }
         }
-        if "svg:desc" desc value "svg:desc/text()";
+        choose{
+            when "$has_continuation" {
+               const "_continuation", "substring-after($desc, $twonewlines)";
+               if "$_continuation"
+                       desc value "$_continuation";
+            }
+            otherwise
+                if "$desc" desc value "$desc/text()";
+        }
     }
 }
 
--- a/tests/projects/svghmi_scrollbar/svghmi_0@svghmi/svghmi.svg	Tue Aug 02 11:53:37 2022 +0200
+++ b/tests/projects/svghmi_scrollbar/svghmi_0@svghmi/svghmi.svg	Thu Aug 11 12:11:35 2022 +0200
@@ -60,12 +60,12 @@
      showgrid="false"
      units="px"
      inkscape:zoom="0.64"
-     inkscape:cx="-438.80601"
-     inkscape:cy="183.59799"
-     inkscape:window-width="3200"
-     inkscape:window-height="1672"
+     inkscape:cx="476.03774"
+     inkscape:cy="444.53549"
+     inkscape:window-width="1600"
+     inkscape:window-height="836"
      inkscape:window-x="0"
-     inkscape:window-y="54"
+     inkscape:window-y="27"
      inkscape:window-maximized="1"
      showguides="true"
      inkscape:guide-bbox="true"
@@ -745,8 +745,14 @@
   </g>
   <g
      id="g4507"
-     inkscape:label="HMI:ScrollBar@.range@.position@.size"
+     inkscape:label="HMI:ScrollBar\"
      transform="translate(-202)">
+    <desc
+       id="desc150">@.range
+@.position
+@.size
+
+my tailor is rich</desc>
     <rect
        y="84"
        x="960"
@@ -857,6 +863,9 @@
      inkscape:label="HMI:ScrollBar@.range@.position@.size"
      id="g156"
      style="stroke-width:2">
+    <desc
+       id="desc149">deedewesfsdf
+cedwee</desc>
     <rect
        inkscape:label="range"
        style="opacity:1;vector-effect:none;fill:#ff35ff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none"