SYNC: better widget panel height processing

This commit is contained in:
SPRINX0\prochazka
2025-12-10 16:24:28 +01:00
committed by Diflow
parent 82ec88cc2f
commit 438f9fc94d

View File

@@ -61,13 +61,11 @@
// First pass: calculate base heights and collect info // First pass: calculate base heights and collect info
let totalFixedHeight = 0; let totalFixedHeight = 0;
let totalFlexibleItems = 0; let totalFlexibleItems = 0;
const itemBaseHeights = {}; const itemHeights = {};
const itemMinHeights = {};
for (const key of visibleItems) { for (const key of visibleItems) {
const def = defs[key]; const def = defs[key];
const minHeight = def.minimalHeight || 0; const minHeight = def.minimalHeight || 100;
itemMinHeights[key] = minHeight;
if (def.height != null) { if (def.height != null) {
let height = 0; let height = 0;
@@ -76,72 +74,33 @@
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);
height = Math.max(height, minHeight); height = Math.max(height, minHeight) + (deltaHeights[key] || 0);
itemBaseHeights[key] = height; if (height < minHeight) height = minHeight;
itemHeights[key] = height;
totalFixedHeight += height; totalFixedHeight += height;
} else { } else {
totalFlexibleItems++; totalFlexibleItems++;
itemBaseHeights[key] = minHeight; // Start with minimum
} }
} }
// Calculate total minimum height needed const availableHeightForFlexible = clientHeight - totalFixedHeight;
let totalMinHeight = 0;
for (const key of visibleItems) {
totalMinHeight += itemMinHeights[key];
}
// Second pass: distribute space // 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) { for (const key of visibleItems) {
itemHeights[key] = itemMinHeights[key] * scale; const def = defs[key];
} const minHeight = def.minimalHeight || 100;
// Clear deltaHeights as they cannot be applied if (def.height == null) {
deltaHeights = {}; let height = availableHeightForFlexible / totalFlexibleItems;
} else if (totalFixedHeight > clientHeight) { if (height < minHeight) height = minHeight;
// Total fixed heights exceed available space - scale proportionally itemHeights[key] = height;
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 sumHeight = _.sum(Object.values(itemHeights));
const newDeltaHeights = {};
for (const key of visibleItems) {
const delta = deltaHeights[key] || 0;
const proposedHeight = itemHeights[key] + delta;
if (proposedHeight >= itemMinHeights[key]) { const ratio = clientHeight / sumHeight;
itemHeights[key] = proposedHeight; for (const key of visibleItems) {
newDeltaHeights[key] = delta; itemHeights[key] = itemHeights[key] * ratio;
} else {
// Delta would violate minimum height, clamp to minimum
itemHeights[key] = itemMinHeights[key];
// Don't preserve this delta
}
}
deltaHeights = newDeltaHeights;
} }
// Build computed result // Build computed result