From 2e38b0268afa07199572c7d786d7ed36882591e6 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Fri, 22 May 2026 00:12:27 -0400 Subject: [PATCH] Fix card stacking overflow when vertical zone has many cards Previously, minOffset (10px) was enforced unconditionally, causing card tops to overflow zone bounds when many cards were stacked. For example, 50 cards in a 200px zone would place the last card's top at y=490. Now offsets compress below minOffset when necessary to keep all card tops visible. The constraint is guarded by !allowBottomOverflow to preserve future clipping zone semantics. --- cockatrice/src/game_graphics/zones/select_zone.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/game_graphics/zones/select_zone.cpp b/cockatrice/src/game_graphics/zones/select_zone.cpp index d43753603..90d53b464 100644 --- a/cockatrice/src/game_graphics/zones/select_zone.cpp +++ b/cockatrice/src/game_graphics/zones/select_zone.cpp @@ -42,7 +42,19 @@ SelectZone::ZoneLayout SelectZone::computeZoneLayout(const StackLayoutParams &pa reservedForBottomCard = params.cardHeight; } fitOffset = (params.totalHeight - reservedForBottomCard) / (params.cardCount - 1); - effectiveOffset = qMax(params.minOffset, qMin(params.desiredOffset, fitOffset)); + + if (!params.allowBottomOverflow) { + // Constrain offset so all card tops remain within zone bounds. + // With start=0, last card top at (cardCount-1) * effectiveOffset must be < totalHeight. + qreal maxOffsetForTops = params.totalHeight / (params.cardCount - 1); + fitOffset = qMin(fitOffset, maxOffsetForTops); + } + + // Apply minOffset only if it fits; otherwise compress further to keep all card tops visible. + effectiveOffset = qMin(params.desiredOffset, fitOffset); + if (fitOffset >= params.minOffset) { + effectiveOffset = qMax(params.minOffset, effectiveOffset); + } } } qreal stackHeight = (params.cardCount - 1) * effectiveOffset + params.cardHeight;