Actions.squeezeColumns: use fillSpace
This commit is contained in:
@@ -250,33 +250,21 @@ class Actions {
|
|||||||
private readonly squeezeColumns = (columns: Column[]) => {
|
private readonly squeezeColumns = (columns: Column[]) => {
|
||||||
const firstColumn = columns[0];
|
const firstColumn = columns[0];
|
||||||
const lastColumn = columns[columns.length-1];
|
const lastColumn = columns[columns.length-1];
|
||||||
const desktop = firstColumn.grid.desktop;
|
const grid = firstColumn.grid;
|
||||||
|
const desktop = grid.desktop;
|
||||||
|
|
||||||
const neededSpace = lastColumn.getRight() - firstColumn.getLeft();
|
|
||||||
const availableSpace = desktop.tilingArea.width;
|
const availableSpace = desktop.tilingArea.width;
|
||||||
let missingSpace = neededSpace - availableSpace;
|
const gapsWidth = grid.config.gapsInnerHorizontal * (columns.length-1);
|
||||||
if (missingSpace <= 0) {
|
const columnConstraints = columns.map(column => ({ min: column.getMinWidth(), max: column.getWidth() }));
|
||||||
// just scroll
|
const minTotalWidth = gapsWidth + columnConstraints.reduce((acc, constraint) => acc + constraint.min, 0);
|
||||||
desktop.scrollCenterRange(Desktop.RangeImpl.fromRanges(firstColumn, lastColumn));
|
if (minTotalWidth > availableSpace) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gainableSpacePerColumn = columns.map(column => column.getWidth() - column.getMinWidth());
|
|
||||||
const gainableSpaceTotal = sum(...gainableSpacePerColumn);
|
|
||||||
if (gainableSpaceTotal < missingSpace) {
|
|
||||||
// there's nothing we can do
|
// there's nothing we can do
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shrinkRatio = missingSpace / gainableSpaceTotal;
|
const widths = fillSpace(availableSpace - gapsWidth, columnConstraints);
|
||||||
for (let i = 0; i < columns.length-1; i++) {
|
columns.forEach((column, index) => column.setWidth(widths[index], true));
|
||||||
const shrinkAmount = Math.round(gainableSpacePerColumn[i] * shrinkRatio);
|
|
||||||
columns[i].adjustWidth(-shrinkAmount, true);
|
|
||||||
missingSpace -= shrinkAmount;
|
|
||||||
}
|
|
||||||
lastColumn.adjustWidth(-missingSpace, true);
|
|
||||||
desktop.scrollCenterRange(Desktop.RangeImpl.fromRanges(firstColumn, lastColumn));
|
desktop.scrollCenterRange(Desktop.RangeImpl.fromRanges(firstColumn, lastColumn));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user