Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sj-Si committed May 20, 2024
1 parent 50a5ad8 commit 17e17ce
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions javascript/resizeGrid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @format */

// Prevent eslint errors on functions defined in other files.
/*global
isNullOrUndefinedThrowError,
Expand Down Expand Up @@ -146,7 +148,6 @@ class ResizeGridItem {
this.min_size = 0;
this.base_size = 0;
}

const dims = this.elem.getBoundingClientRect();
this.base_size =
this.axis === 0 ? parseInt(dims.height) : parseInt(dims.width);
Expand Down Expand Up @@ -375,6 +376,14 @@ class ResizeGridContainer {
for (let j = 0; j < this.grid[i].length; j++) {
this.grid[i][j].render({reset: true});
}
const vis_cols = this.grid[i].filter((x) => x.visible);
if (vis_cols.length === 1) {
vis_cols[0].render({force_flex_grow: true});
}
}
const vis_rows = this.rows.filter((x) => x.visible);
if (vis_rows.length === 1) {
vis_rows[0].render({force_flex_grow: true});
}
}

Expand Down Expand Up @@ -523,7 +532,7 @@ class ResizeGridContainer {
throw new Error(`No space for row. tot: ${tot}, rem: ${rem}`);
}

growToFill(item, siblings, item_idx, tot_px, max_px) {
growToFill(item, siblings, item_idx, tot_px) {
/** Expands item along axis until the axis has no remaining space. */
// Expand the item that was attached via the hidden item's handle first.
let sibling = siblings.slice(item_idx + 1).find((x) => x.visible);
Expand Down Expand Up @@ -553,11 +562,7 @@ class ResizeGridContainer {
) {
sibling.render({force_flex_grow: true});
} else {
const sibling_size = sibling.getSize();
if (tot_px + sibling_size > max_px) {
tot_px = max_px - sibling_size;
}
sibling.grow(tot_px);
sibling.grow(-1);
}
}

Expand Down Expand Up @@ -661,15 +666,14 @@ class ResizeGridContainer {
return;
}

const max_height = this.elem.getBoundingClientRect().height;
let tot_px = item.elem.getBoundingClientRect().height;
item.hide();
// If no other rows are visible, we don't need to do anything else.
if (this.rows.every((x) => !x.visible)) {
return;
}

this.growToFill(item, this.rows, row_idx, tot_px, max_height);
this.growToFill(item, this.rows, row_idx, tot_px);
}

hideCol(row_idx, col_idx) {
Expand All @@ -688,16 +692,15 @@ class ResizeGridContainer {
return;
}

const max_width = this.elem.getBoundingClientRect().width;
let tot_px = item.elem.getBoundingClientRect().width;
let tot_px = item.getSize();
item.hide();
// If no other cols are visible, hide the containing row.
if (this.grid[row_idx].every((x) => !x.visible)) {
this.hideRow(row_idx);
return;
}

this.growToFill(item, this.grid[row_idx], col_idx, tot_px, max_width);
this.growToFill(item, this.grid[row_idx], col_idx, tot_px);
}

show({row_idx, col_idx} = {}) {
Expand Down

0 comments on commit 17e17ce

Please sign in to comment.