# HG changeset patch
# User Edouard Tisserant
# Date 1582298564 -3600
# Node ID 2f73f001955a248e6f1a7c5fb33b35f9f164e904
# Parent 7c6050cde9e3e3276b78e502e52774ce843036bc
SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
diff -r 7c6050cde9e3 -r 2f73f001955a svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Fri Feb 21 16:18:53 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Fri Feb 21 16:22:44 2020 +0100
@@ -102,8 +102,8 @@
-
-
+
+
+
@@ -126,6 +126,40 @@
All units must be set to "px" in Inkscape's document properties
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Made with SVGHMI. https://beremiz.org
@@ -139,7 +173,7 @@
-
+
@@ -333,9 +367,9 @@
": {
- id: "
+ widget: hmi_widgets["
- ",
+ "],
bbox: [
@@ -824,17 +858,65 @@
let new_desc = page_desc[page_name];
- /* TODO hide / show widgets */
+
+
+ if(new_desc == undefined){
+
+ return;
+
+ }
/* remove subsribers of previous page if any */
- if(old_desc) for(let widget of old_desc.widgets){
+ if(old_desc){
+
+ for(let widget of old_desc.widgets){
+
+ for(let index of widget.indexes){
+
+ subscribers[index].delete(widget);
+
+ }
+
+ }
+
+ old_desc.widget.element.style.display = "none";
+
+ } else {
+
+ /* initial page switch : set everybody hidden */
+
+ for(let name in page_desc){
+
+ if(name != new_desc){
+
+ page_desc[name].widget.element.style.display = "none";
+
+ }
+
+ }
+
+ }
+
+
+
+ /* add new subsribers if any */
+
+ for(let widget of new_desc.widgets){
for(let index of widget.indexes){
- subscribers[index].delete(widget);
+ subscribers[index].add(widget);
+
+ /* dispatch current cache in newly opened page widgets */
+
+ let cached_val = cache[index];
+
+ if(cached_val != undefined)
+
+ dispatch_value_to_widget(widget, index, cached_val, cached_val);
}
@@ -842,31 +924,11 @@
- if(new_desc) {
-
- /* add new subsribers if any */
-
- for(let widget of new_desc.widgets){
-
- for(let index of widget.indexes){
-
- subscribers[index].add(widget);
-
- let cached_val = cache[index];
-
- if(cached_val != undefined)
-
- dispatch_value_to_widget(widget, index, cached_val, cached_val);
-
- }
-
- }
-
- svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
-
- // TODO dispatch current cache in newly opened page
-
- }
+ new_desc.widget.element.style.display = "inline";
+
+
+
+ svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
current_page = page_name;
diff -r 7c6050cde9e3 -r 2f73f001955a svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Fri Feb 21 16:18:53 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Fri Feb 21 16:22:44 2020 +0100
@@ -133,6 +133,43 @@
error > All units must be set to "px" in Inkscape's document properties
}
+ /* clone unlinkink until widget for better perf with webkit */
+ svgtmpl "svg:use", mode="inline_svg"
+ {
+ g{
+ attrib "style" > «@style»
+ attrib "transform" > «@transform»
+ /* keep same id and label in case it is a widget */
+ //attrib "inkscape:label","@inkscape:label";
+ attrib "id" > «@id»
+ const "targetid","substring-after(@xlink:href,'#')";
+ apply "//svg:*[@id = $targetid]", mode="unlink_clone";
+ }
+ }
+ svgtmpl "@*", mode="unlink_clone" xsl:copy;
+ svgtmpl "svg:*", mode="unlink_clone" {
+ choose {
+ when "@id = $hmi_elements/@id" {
+ use{
+ attrib "xlink:href" > «concat('#',@id)»
+ }
+ }
+ otherwise {
+ xsl:copy apply "@* | node()", mode="unlink_clone";
+ }
+ }
+ }
+
+ // template "svg:use/@style", mode="inline_svg"{
+ // attrib "style" > all:initial;
+ // //«.»
+ // }
+
+ // template "svg:*[concat('#',@id) = //svg:use/@xlink:href]/@style", mode="inline_svg"{
+ // attrib "style" > all:unset;
+ // //«.»
+ // }
+
/*const "mark" > =HMI=\n*/
/* copy root node and add geometry as comment for a test */