# HG changeset patch # User Edouard Tisserant # Date 1729086315 -7200 # Node ID b3ea419a4d474b98f2f516a6b061b8b1df7bd3c8 # Parent 5234d06f62eeb8fe97a0d182c3dac835b609d8da SVGHMI: swap position and range of ForEach widget so that both range and size can be optional. diff -r 5234d06f62ee -r b3ea419a4d47 exemples/svghmi_foreach/svghmi_0@svghmi/svghmi.svg --- a/exemples/svghmi_foreach/svghmi_0@svghmi/svghmi.svg Wed Nov 27 16:05:26 2024 +0100 +++ b/exemples/svghmi_foreach/svghmi_0@svghmi/svghmi.svg Wed Oct 16 15:45:15 2024 +0200 @@ -220,7 +220,7 @@ sodipodi:role="line">8888 8888 sub(new_offset, relativeness, container_id){ - let position_given = this.indexes.length > 2; + let position_given = this.indexes.length > 1; @@ -4713,9 +4713,13 @@ // as soon as subribed apply range and size once for all - this.apply_hmi_value(1, this.range); - - this.apply_hmi_value(3, this.size); + if(this.indexes.length > 2) + + this.apply_hmi_value(2, this.range); + + if(this.indexes.length > 3) + + this.apply_hmi_value(3, this.size); } @@ -4779,7 +4783,7 @@ if(this.apply_position(new_position)){ - this.apply_hmi_value(2, this.position); + this.apply_hmi_value(1, this.position); } @@ -4791,7 +4795,7 @@ // Only care about position, others are constants - if(index == 2){ + if(index == 1){ this.apply_position(value); @@ -4799,7 +4803,7 @@ // widget refused or apply different value, force it back - this.apply_hmi_value(2, this.position); + this.apply_hmi_value(1, this.position); } diff -r 5234d06f62ee -r b3ea419a4d47 svghmi/widget_foreach.ysl2 --- a/svghmi/widget_foreach.ysl2 Wed Nov 27 16:05:26 2024 +0100 +++ b/svghmi/widget_foreach.ysl2 Wed Oct 16 15:45:15 2024 +0200 @@ -29,6 +29,9 @@ arg name="class_name" accepts="string" > HMI_CLASS name path name="root" accepts="HMI_NODE" > where to find HMI_NODEs whose HMI_CLASS is class_name + path name="position" accepts="HMI_INT" > position of HMI_NODE mapped to first item, among similar siblings + path name="range" accepts="HMI_INT" count="optional" > count of HMI_NODE siblings + path name="size" accepts="HMI_INT" count="optional" > count of visible items } widget_defs("ForEach") { @@ -125,7 +128,7 @@ } sub(new_offset, relativeness, container_id){ - let position_given = this.indexes.length > 2; + let position_given = this.indexes.length > 1; // sub() will call apply_cache() and then dispatch() // undefining position forces dispatch() to call apply_position() @@ -141,8 +144,10 @@ this.sub_items(); // as soon as subribed apply range and size once for all - this.apply_hmi_value(1, this.range); - this.apply_hmi_value(3, this.size); + if(this.indexes.length > 2) + this.apply_hmi_value(2, this.range); + if(this.indexes.length > 3) + this.apply_hmi_value(3, this.size); } apply_position(new_position){ @@ -174,17 +179,17 @@ new_position = 0; } if(this.apply_position(new_position)){ - this.apply_hmi_value(2, this.position); + this.apply_hmi_value(1, this.position); } } dispatch(value, oldval, index) { // Only care about position, others are constants - if(index == 2){ + if(index == 1){ this.apply_position(value); if(this.position != value){ // widget refused or apply different value, force it back - this.apply_hmi_value(2, this.position); + this.apply_hmi_value(1, this.position); } } }