# HG changeset patch # User Edouard Tisserant # Date 1588949503 -7200 # Node ID e50908ddec60460a225fa838a30dca1a095a9b35 # Parent faaf677ea99da509b88b31a0632b652d50f40d4b SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets. diff -r faaf677ea99d -r e50908ddec60 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Fri May 08 16:47:52 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Fri May 08 16:51:43 2020 +0200 @@ -1,6 +1,6 @@ - - + + @@ -19,6 +19,14 @@ + + + /* + + */ + + + var hmi_hash = [ ]; @@ -51,6 +59,8 @@ + + @@ -215,6 +225,14 @@ + + + /* + + */ + + + Raw HMI tree @@ -229,10 +247,20 @@ + + + + + /* + + */ + + + ID, x, y, w, h @@ -249,6 +277,8 @@ + + @@ -322,10 +352,20 @@ + /* + + */ + + + + + var default_page = " "; + + @@ -387,6 +427,14 @@ + /* + + */ + + + + + var detachable_elements = { @@ -405,6 +453,8 @@ } + + @@ -531,17 +581,35 @@ + /* + + */ + + + + + var page_desc = { } + + + /* + + */ + + + + + DETACHABLES: @@ -558,6 +626,8 @@ + + @@ -672,17 +742,35 @@ + + + /* + + */ + + + let id = document.getElementById.bind(document); var svg_root = id(" "); + + + /* + + */ + + + + + Unlinked : @@ -690,17 +778,17 @@ + + " - ": { - - type: " + ": new - ", + Widget ({ args: [ @@ -759,20 +847,99 @@ - } + }) , + + + + + + + + + + + + + + + + + + + + + + + + /* + + */ + + + + class Widget { + + constructor(members){ + + Object.keys(members).forEach(prop => this[prop]=members[prop]); + + } + + } + + + + + + + + + /* + + */ + + + + + + + + + + class + + Widget extends Widget{ + + /* empty class, as + + widget didn't provide any */ + + } + + + + + /* + + */ + + + var hmi_widgets = { } + + sub: subscribe, @@ -1671,6 +1838,14 @@ + + + /* + + */ + + + function foreach_unsubscribe(){ for(let item of this.items){ @@ -1777,6 +1952,8 @@ + + @@ -2083,6 +2260,14 @@ + + + /* + + */ + + + var jumps_need_update = false; var jump_history = [[default_page, undefined]]; @@ -2099,11 +2284,21 @@ + + + /* + + */ + + + + + var keypads = { @@ -2124,6 +2319,8 @@ } + + @@ -2453,15 +2650,10 @@ Made with SVGHMI. https://beremiz.org - - - - : - - - - - + + + + diff -r faaf677ea99d -r e50908ddec60 svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Fri May 08 16:47:52 2020 +0200 +++ b/svghmi/widgets_common.ysl2 Fri May 08 16:51:43 2020 +0200 @@ -24,8 +24,7 @@ template "svg:*", mode="hmi_elements" { const "widget", "func:widget(@id)"; const "eltid","@id"; - | "«@id»": { - | type: "«$widget/@type»", + | "«@id»": new «$widget/@type»Widget ({ | args: [ foreach "$widget/arg" | "«@value»"`if "position()!=last()" > ,` @@ -46,7 +45,8 @@ | element: id("«@id»"), apply "$widget", mode="widget_defs" with "hmi_element","."; apply "$widget", mode="widget_subscribe" with "hmi_element","."; - | }`if "position()!=last()" > ,` + | })`if "position()!=last()" > ,` +} def "func:unique_types" { param "elts_with_type"; @@ -69,17 +69,35 @@ } } +emit "preamble:widget-base-class" { + || + class Widget { + constructor(members){ + Object.keys(members).forEach(prop => this[prop]=members[prop]); + } + } + || +} + emit "preamble:hmi-classes" { const "used_widget_types", "func:unique_types($parsed_widgets/widget)"; apply "$used_widget_types", mode="widget_class"; } +template "widget", mode="widget_class" +|| +class «@type»Widget extends Widget{ + /* empty class, as «@type» widget didn't provide any */ +} +|| + emit "preamble:hmi-elements" { | var hmi_widgets = { apply "$hmi_elements", mode="hmi_elements"; | } } + // default : normal subscribing template "widget", mode="widget_subscribe" { | sub: subscribe,