mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 02:36:01 +00:00
SYNC: resize WIP
This commit is contained in:
committed by
Diflow
parent
90d3016938
commit
3d2ad1cb9b
@@ -58,62 +58,72 @@
|
|||||||
|
|
||||||
const computed = {};
|
const computed = {};
|
||||||
|
|
||||||
// First pass: calculate base heights and collect info
|
// First pass: calculate base heights
|
||||||
let totalFixedHeight = 0;
|
let totalFixedHeight = 0;
|
||||||
let totalFlexibleItems = 0;
|
let totalFlexibleItems = 0;
|
||||||
const itemHeights = {};
|
const itemHeights = {};
|
||||||
|
const isResized = {};
|
||||||
|
|
||||||
for (const key of visibleItems) {
|
for (const key of visibleItems) {
|
||||||
const def = defs[key];
|
const def = defs[key];
|
||||||
const minHeight = def.minimalHeight || 100;
|
const minHeight = def.minimalHeight || 100;
|
||||||
|
|
||||||
if (def.height != null) {
|
// Check if this item has a user-resized height
|
||||||
|
if (key in resizedHeights) {
|
||||||
|
itemHeights[key] = Math.max(resizedHeights[key], minHeight);
|
||||||
|
isResized[key] = true;
|
||||||
|
totalFixedHeight += itemHeights[key];
|
||||||
|
} else if (def.height != null) {
|
||||||
let height = 0;
|
let height = 0;
|
||||||
if (_.isString(def.height) && def.height.endsWith('px')) height = parseInt(def.height.slice(0, -2));
|
if (_.isString(def.height) && def.height.endsWith('px')) height = parseInt(def.height.slice(0, -2));
|
||||||
else if (_.isString(def.height) && def.height.endsWith('%'))
|
else if (_.isString(def.height) && def.height.endsWith('%'))
|
||||||
height = (clientHeight * parseFloat(def.height.slice(0, -1))) / 100;
|
height = (clientHeight * parseFloat(def.height.slice(0, -1))) / 100;
|
||||||
else height = parseInt(def.height);
|
else height = parseInt(def.height);
|
||||||
|
|
||||||
if (key in resizedHeights) height = resizedHeights[key];
|
height = Math.max(height, minHeight);
|
||||||
if (height < minHeight) height = minHeight;
|
|
||||||
itemHeights[key] = height;
|
itemHeights[key] = height;
|
||||||
|
isResized[key] = false;
|
||||||
totalFixedHeight += height;
|
totalFixedHeight += height;
|
||||||
} else {
|
} else {
|
||||||
|
isResized[key] = false;
|
||||||
totalFlexibleItems++;
|
totalFlexibleItems++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Second pass: distribute remaining space to flexible items
|
||||||
const availableHeightForFlexible = clientHeight - totalFixedHeight;
|
const availableHeightForFlexible = clientHeight - totalFixedHeight;
|
||||||
|
|
||||||
// Second pass: distribute space
|
|
||||||
for (const key of visibleItems) {
|
for (const key of visibleItems) {
|
||||||
const def = defs[key];
|
if (!(key in itemHeights)) {
|
||||||
const minHeight = def.minimalHeight || 100;
|
const def = defs[key];
|
||||||
if (def.height == null) {
|
const minHeight = def.minimalHeight || 100;
|
||||||
let height = availableHeightForFlexible / totalFlexibleItems;
|
let height = totalFlexibleItems > 0 ? availableHeightForFlexible / totalFlexibleItems : minHeight;
|
||||||
if (height < minHeight) height = minHeight;
|
height = Math.max(height, minHeight);
|
||||||
itemHeights[key] = height;
|
itemHeights[key] = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sumHeight = _.sum(Object.values(itemHeights));
|
// Third pass: scale all non-resized items proportionally to fill clientHeight exactly
|
||||||
|
const totalHeight = _.sum(Object.values(itemHeights));
|
||||||
|
const resizedKeys = Object.keys(isResized).filter(k => isResized[k]);
|
||||||
|
const nonResizedKeys = visibleItems.filter(k => !isResized[k]);
|
||||||
|
|
||||||
const ratio = clientHeight / sumHeight;
|
if (totalHeight !== clientHeight && nonResizedKeys.length > 0) {
|
||||||
for (const key of visibleItems) {
|
const totalResizedHeight = _.sum(resizedKeys.map(k => itemHeights[k]));
|
||||||
itemHeights[key] = itemHeights[key] * ratio;
|
const totalNonResizedHeight = _.sum(nonResizedKeys.map(k => itemHeights[k]));
|
||||||
}
|
const availableForNonResized = clientHeight - totalResizedHeight;
|
||||||
|
|
||||||
// third pass - overwrite with resized heights
|
if (totalNonResizedHeight > 0 && availableForNonResized > 0) {
|
||||||
for (const key of visibleItems) {
|
const ratio = availableForNonResized / totalNonResizedHeight;
|
||||||
if (key in resizedHeights) {
|
for (const key of nonResizedKeys) {
|
||||||
itemHeights[key] = resizedHeights[key];
|
itemHeights[key] = itemHeights[key] * ratio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (totalHeight !== clientHeight && nonResizedKeys.length === 0) {
|
||||||
|
// All items are resized, scale proportionally
|
||||||
|
const ratio = clientHeight / totalHeight;
|
||||||
|
for (const key of visibleItems) {
|
||||||
|
itemHeights[key] = itemHeights[key] * ratio;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// fix total height again
|
|
||||||
const ratio2 = clientHeight / _.sum(Object.values(itemHeights));
|
|
||||||
for (const key of visibleItems) {
|
|
||||||
itemHeights[key] = itemHeights[key] * ratio2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build computed result
|
// Build computed result
|
||||||
@@ -127,8 +137,7 @@
|
|||||||
visibleIndex++;
|
visibleIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('WidgetColumnBar definitions', defs);
|
// Clean up resizedHeights - remove entries for items that no longer exist
|
||||||
// console.log('WidgetColumnBar recompute', computed);
|
|
||||||
resizedHeights = _.pickBy(
|
resizedHeights = _.pickBy(
|
||||||
_.mapValues(resizedHeights, (v, k) => {
|
_.mapValues(resizedHeights, (v, k) => {
|
||||||
if (k in itemHeights) return v;
|
if (k in itemHeights) return v;
|
||||||
|
|||||||
Reference in New Issue
Block a user