@@ -124,7 +124,7 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
124
124
// set percent only to cells without one
125
125
for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
126
126
if (!widths [i ].isPercent ) {
127
- widths [i ].setPercents (percentAddition / pointColumns ). setFixed ( true ) ;
127
+ widths [i ].setPercents (percentAddition / pointColumns );
128
128
}
129
129
}
130
130
}
@@ -145,7 +145,9 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
145
145
for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
146
146
if (!widths [i ].isPercent ) {
147
147
colspanRemain -= widths [i ].width ;
148
- if (!widths [i ].isFixed ) flexibleCols ++;
148
+ if (!widths [i ].isFixed ){
149
+ flexibleCols ++;
150
+ }
149
151
} else {
150
152
colspanRemain = -1 ;
151
153
break ;
@@ -155,16 +157,18 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
155
157
if (flexibleCols > 0 ) {
156
158
// check min width in columns
157
159
for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
158
- if (! widths [i ].isFixed && widths [i ].checkCollision (colspanRemain / flexibleCols )) {
160
+ if (widths [i ].isFlexible () && widths [i ].checkCollision (colspanRemain / flexibleCols )) {
159
161
widths [i ].setPoints (widths [i ].min ).setFixed (true );
160
- if ((colspanRemain -= widths [i ].min ) <= 0 || flexibleCols -- <= 0 ) {
162
+ colspanRemain -= widths [i ].min ;
163
+ flexibleCols --;
164
+ if (colspanRemain <= 0 || flexibleCols <= 0 ) {
161
165
break ;
162
166
}
163
167
}
164
168
}
165
169
if (colspanRemain > 0 && flexibleCols > 0 ) {
166
170
for (int k = cell .getCol (); k < cell .getCol () + cell .getColspan (); k ++) {
167
- if (! widths [k ].isFixed ) {
171
+ if (widths [k ].isFlexible () ) {
168
172
widths [k ].addPoints (colspanRemain / flexibleCols ).setFixed (true );
169
173
}
170
174
}
@@ -177,26 +181,20 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
177
181
}
178
182
}
179
183
}
180
- } else if (! widths [cell .getCol ()].isFixed ) {
184
+ } else if (widths [cell .getCol ()].isFlexible () ) {
181
185
//if there is no information, try to set max width
182
186
int flexibleCols = 0 ;
183
187
float remainWidth = 0 ;
184
188
for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
185
- if (! widths [i ].isFixed && ! widths [ i ]. isPercent ) {
189
+ if (widths [i ].isFlexible () ) {
186
190
remainWidth += widths [i ].max - widths [i ].width ;
187
191
flexibleCols ++;
188
192
}
189
193
}
190
- if (remainWidth > 0 ) {
191
- if (flexibleCols > 0 ) {
192
- for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
193
- if (!widths [i ].isFixed && !widths [i ].isPercent ) {
194
- widths [i ].addPoints (remainWidth / flexibleCols );
195
- }
196
- }
197
- } else {
198
- for (int k = cell .getCol (); k < cell .getCol () + cell .getColspan (); k ++) {
199
- widths [k ].addPoints (remainWidth / cell .getColspan ());
194
+ if (remainWidth > 0 ) { // flexibleCols > 0 too
195
+ for (int i = cell .getCol (); i < cell .getCol () + cell .getColspan (); i ++) {
196
+ if (widths [i ].isFlexible ()) {
197
+ widths [i ].addPoints (remainWidth / flexibleCols );
200
198
}
201
199
}
202
200
}
@@ -217,19 +215,17 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
217
215
UnitValue colWidth = getTable ().getColumnWidth (i );
218
216
if (colWidth .getValue () >= 0 ) {
219
217
if (colWidth .isPercentValue ()) {
220
- if (!widths [i ].isPercent && widths [i ].isFixed && widths [i ].width > widths [i ].min ) {
221
- widths [i ].max = widths [i ].width ;
222
- widths [i ].setFixed (false );
223
- }
224
218
if (!widths [i ].isPercent ) {
219
+ if (widths [i ].isFixed && widths [i ].width > widths [i ].min ) {
220
+ widths [i ].max = widths [i ].width ;
221
+ }
225
222
widths [i ].setPercents (colWidth .getValue ());
226
223
}
227
-
228
224
} else if (!widths [i ].isPercent && colWidth .getValue () >= widths [i ].min ) {
229
225
if (widths [i ].isFixed ) {
230
226
widths [i ].setPoints (colWidth .getValue ());
231
227
} else {
232
- widths [i ].resetPoints (colWidth .getValue ());
228
+ widths [i ].resetPoints (colWidth .getValue ()). setFixed ( true ) ;
233
229
}
234
230
}
235
231
}
@@ -256,7 +252,7 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
256
252
warn100percent ();
257
253
} else if (sumOfPercents >= 100 ) {
258
254
widths [i ].resetPoints (widths [i ].min );
259
- minTableWidth += widths [i ].width ;
255
+ minTableWidth += widths [i ].min ;
260
256
warn100percent ();
261
257
} else {
262
258
sumOfPercents += widths [i ].width ;
@@ -277,6 +273,7 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
277
273
tableWidthBasedOnPercents = Math .max (widths [i ].max * 100 / widths [i ].width , tableWidthBasedOnPercents );
278
274
}
279
275
}
276
+
280
277
if (tableWidthBasedOnPercents <= tableWidth ) {
281
278
tableWidth = tableWidthBasedOnPercents ;
282
279
//we don't need more space, columns are done based on column's max width.
@@ -375,33 +372,30 @@ float[] autoLayout(float[] minWidths, float[] maxWidths) {
375
372
float extraWidth = tableWidth - totalPercent - minTotalNonPercent ;
376
373
if (fixedAddition > 0 && (extraWidth < fixedAddition || flexibleAddition == 0 )) {
377
374
for (int i = 0 ; i < numberOfColumns ; i ++) {
378
- if (!widths [i ].isPercent && widths [i ].isFixed ) {
375
+ //only points could be fixed
376
+ if (widths [i ].isFixed ) {
379
377
widths [i ].finalWidth += (widths [i ].width - widths [i ].min ) * extraWidth / fixedAddition ;
380
378
}
381
379
}
382
380
} else {
383
381
extraWidth -= fixedAddition ;
384
382
if (extraWidth < flexibleAddition ) {
385
383
for (int i = 0 ; i < numberOfColumns ; i ++) {
386
- if (!widths [i ].isPercent ) {
387
- if (widths [i ].isFixed ) {
388
- widths [i ].finalWidth = widths [i ].width ;
389
- } else {
390
- widths [i ].finalWidth += (widths [i ].width - widths [i ].min ) * extraWidth / flexibleAddition ;
391
- }
384
+ if (widths [i ].isFixed ) {
385
+ widths [i ].finalWidth = widths [i ].width ;
386
+ } else if (!widths [i ].isPercent ) {
387
+ widths [i ].finalWidth += (widths [i ].width - widths [i ].min ) * extraWidth / flexibleAddition ;
392
388
}
393
389
}
394
390
} else {
395
391
float totalFixed = 0 ;
396
392
float totalFlexible = 0 ;
397
393
for (int i = 0 ; i < numberOfColumns ; i ++) {
398
- if (!widths [i ].isPercent ) {
399
- if (widths [i ].isFixed ) {
400
- widths [i ].finalWidth = widths [i ].width ;
401
- totalFixed += widths [i ].width ;
402
- } else {
403
- totalFlexible += widths [i ].width ;
404
- }
394
+ if (widths [i ].isFixed ) {
395
+ widths [i ].finalWidth = widths [i ].width ;
396
+ totalFixed += widths [i ].width ;
397
+ } else if (!widths [i ].isPercent ) {
398
+ totalFlexible += widths [i ].width ;
405
399
}
406
400
}
407
401
extraWidth = tableWidth - totalPercent - totalFixed ;
@@ -635,6 +629,7 @@ ColumnWidthData setPercents(float percent) {
635
629
isPercent = true ;
636
630
width = percent ;
637
631
}
632
+ isFixed = false ;
638
633
return this ;
639
634
}
640
635
@@ -649,6 +644,10 @@ ColumnWidthData setFixed(boolean fixed) {
649
644
return this ;
650
645
}
651
646
647
+ boolean isFlexible () {
648
+ return !this .isFixed && !this .isPercent ;
649
+ }
650
+
652
651
/**
653
652
* Check collusion between min value and point width
654
653
*
0 commit comments