equal
deleted
inserted
replaced
27 shortdesc > span widgets over a set of repeated HMI_NODEs |
27 shortdesc > span widgets over a set of repeated HMI_NODEs |
28 |
28 |
29 arg name="class_name" accepts="string" > HMI_CLASS name |
29 arg name="class_name" accepts="string" > HMI_CLASS name |
30 |
30 |
31 path name="root" accepts="HMI_NODE" > where to find HMI_NODEs whose HMI_CLASS is class_name |
31 path name="root" accepts="HMI_NODE" > where to find HMI_NODEs whose HMI_CLASS is class_name |
|
32 path name="position" accepts="HMI_INT" > position of HMI_NODE mapped to first item, among similar siblings |
|
33 path name="range" accepts="HMI_INT" count="optional" > count of HMI_NODE siblings |
|
34 path name="size" accepts="HMI_INT" count="optional" > count of visible items |
32 } |
35 } |
33 |
36 |
34 widget_defs("ForEach") { |
37 widget_defs("ForEach") { |
35 |
38 |
36 if "count(path) < 1" error > ForEach widget «$hmi_element/@id» must have one HMI path given. |
39 if "count(path) < 1" error > ForEach widget «$hmi_element/@id» must have one HMI path given. |
123 } |
126 } |
124 } |
127 } |
125 } |
128 } |
126 |
129 |
127 sub(new_offset, relativeness, container_id){ |
130 sub(new_offset, relativeness, container_id){ |
128 let position_given = this.indexes.length > 2; |
131 let position_given = this.indexes.length > 1; |
129 |
132 |
130 // sub() will call apply_cache() and then dispatch() |
133 // sub() will call apply_cache() and then dispatch() |
131 // undefining position forces dispatch() to call apply_position() |
134 // undefining position forces dispatch() to call apply_position() |
132 if(position_given) |
135 if(position_given) |
133 this.position = undefined; |
136 this.position = undefined; |
139 // and items must be subscibed now. |
142 // and items must be subscibed now. |
140 if(!position_given) |
143 if(!position_given) |
141 this.sub_items(); |
144 this.sub_items(); |
142 |
145 |
143 // as soon as subribed apply range and size once for all |
146 // as soon as subribed apply range and size once for all |
144 this.apply_hmi_value(1, this.range); |
147 if(this.indexes.length > 2) |
145 this.apply_hmi_value(3, this.size); |
148 this.apply_hmi_value(2, this.range); |
|
149 if(this.indexes.length > 3) |
|
150 this.apply_hmi_value(3, this.size); |
146 } |
151 } |
147 |
152 |
148 apply_position(new_position){ |
153 apply_position(new_position){ |
149 let old_position = this.position; |
154 let old_position = this.position; |
150 let limited_position = Math.round(Math.max(Math.min(new_position, this.range - this.size), 0)); |
155 let limited_position = Math.round(Math.max(Math.min(new_position, this.range - this.size), 0)); |
172 new_position = this.range - this.size; |
177 new_position = this.range - this.size; |
173 else |
178 else |
174 new_position = 0; |
179 new_position = 0; |
175 } |
180 } |
176 if(this.apply_position(new_position)){ |
181 if(this.apply_position(new_position)){ |
177 this.apply_hmi_value(2, this.position); |
182 this.apply_hmi_value(1, this.position); |
178 } |
183 } |
179 } |
184 } |
180 |
185 |
181 dispatch(value, oldval, index) { |
186 dispatch(value, oldval, index) { |
182 // Only care about position, others are constants |
187 // Only care about position, others are constants |
183 if(index == 2){ |
188 if(index == 1){ |
184 this.apply_position(value); |
189 this.apply_position(value); |
185 if(this.position != value){ |
190 if(this.position != value){ |
186 // widget refused or apply different value, force it back |
191 // widget refused or apply different value, force it back |
187 this.apply_hmi_value(2, this.position); |
192 this.apply_hmi_value(1, this.position); |
188 } |
193 } |
189 } |
194 } |
190 } |
195 } |
191 |
196 |
192 || |
197 || |