mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
SYNC: better widget panel height processing
This commit is contained in:
committed by
Diflow
parent
82ec88cc2f
commit
438f9fc94d
@@ -61,87 +61,46 @@
|
||||
// First pass: calculate base heights and collect info
|
||||
let totalFixedHeight = 0;
|
||||
let totalFlexibleItems = 0;
|
||||
const itemBaseHeights = {};
|
||||
const itemMinHeights = {};
|
||||
|
||||
const itemHeights = {};
|
||||
|
||||
for (const key of visibleItems) {
|
||||
const def = defs[key];
|
||||
const minHeight = def.minimalHeight || 0;
|
||||
itemMinHeights[key] = minHeight;
|
||||
|
||||
const minHeight = def.minimalHeight || 100;
|
||||
|
||||
if (def.height != null) {
|
||||
let height = 0;
|
||||
if (_.isString(def.height) && def.height.endsWith('px')) height = parseInt(def.height.slice(0, -2));
|
||||
else if (_.isString(def.height) && def.height.endsWith('%'))
|
||||
height = (clientHeight * parseFloat(def.height.slice(0, -1))) / 100;
|
||||
else height = parseInt(def.height);
|
||||
|
||||
height = Math.max(height, minHeight);
|
||||
itemBaseHeights[key] = height;
|
||||
|
||||
height = Math.max(height, minHeight) + (deltaHeights[key] || 0);
|
||||
if (height < minHeight) height = minHeight;
|
||||
itemHeights[key] = height;
|
||||
totalFixedHeight += height;
|
||||
} else {
|
||||
totalFlexibleItems++;
|
||||
itemBaseHeights[key] = minHeight; // Start with minimum
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate total minimum height needed
|
||||
let totalMinHeight = 0;
|
||||
for (const key of visibleItems) {
|
||||
totalMinHeight += itemMinHeights[key];
|
||||
}
|
||||
const availableHeightForFlexible = clientHeight - totalFixedHeight;
|
||||
|
||||
// Second pass: distribute space
|
||||
const itemHeights = {};
|
||||
|
||||
if (totalMinHeight > clientHeight) {
|
||||
// Scale proportionally - all items get their minimum height scaled down
|
||||
const scale = clientHeight / totalMinHeight;
|
||||
for (const key of visibleItems) {
|
||||
itemHeights[key] = itemMinHeights[key] * scale;
|
||||
for (const key of visibleItems) {
|
||||
const def = defs[key];
|
||||
const minHeight = def.minimalHeight || 100;
|
||||
if (def.height == null) {
|
||||
let height = availableHeightForFlexible / totalFlexibleItems;
|
||||
if (height < minHeight) height = minHeight;
|
||||
itemHeights[key] = height;
|
||||
}
|
||||
// Clear deltaHeights as they cannot be applied
|
||||
deltaHeights = {};
|
||||
} else if (totalFixedHeight > clientHeight) {
|
||||
// Total fixed heights exceed available space - scale proportionally
|
||||
const scale = clientHeight / totalFixedHeight;
|
||||
for (const key of visibleItems) {
|
||||
const scaledHeight = itemBaseHeights[key] * scale;
|
||||
itemHeights[key] = Math.max(scaledHeight, itemMinHeights[key] * scale);
|
||||
}
|
||||
// Clear deltaHeights as they cannot be applied reliably
|
||||
deltaHeights = {};
|
||||
} else {
|
||||
// Distribute remaining space among flexible items
|
||||
const remainingHeight = clientHeight - totalFixedHeight;
|
||||
const flexibleSpace = totalFlexibleItems > 0 ? remainingHeight / totalFlexibleItems : 0;
|
||||
|
||||
for (const key of visibleItems) {
|
||||
if (itemBaseHeights[key] === itemMinHeights[key] && totalFlexibleItems > 0) {
|
||||
// Flexible item
|
||||
itemHeights[key] = Math.max(flexibleSpace, itemMinHeights[key]);
|
||||
} else {
|
||||
// Fixed item
|
||||
itemHeights[key] = itemBaseHeights[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Apply deltaHeights while respecting minimum heights
|
||||
const newDeltaHeights = {};
|
||||
for (const key of visibleItems) {
|
||||
const delta = deltaHeights[key] || 0;
|
||||
const proposedHeight = itemHeights[key] + delta;
|
||||
|
||||
if (proposedHeight >= itemMinHeights[key]) {
|
||||
itemHeights[key] = proposedHeight;
|
||||
newDeltaHeights[key] = delta;
|
||||
} else {
|
||||
// Delta would violate minimum height, clamp to minimum
|
||||
itemHeights[key] = itemMinHeights[key];
|
||||
// Don't preserve this delta
|
||||
}
|
||||
}
|
||||
deltaHeights = newDeltaHeights;
|
||||
}
|
||||
|
||||
const sumHeight = _.sum(Object.values(itemHeights));
|
||||
|
||||
const ratio = clientHeight / sumHeight;
|
||||
for (const key of visibleItems) {
|
||||
itemHeights[key] = itemHeights[key] * ratio;
|
||||
}
|
||||
|
||||
// Build computed result
|
||||
|
||||
Reference in New Issue
Block a user