tooltip: clamp box width to client on narrow panels; add narrow-client test

This commit is contained in:
2026-07-27 00:05:14 -04:00
parent 7cd0771e45
commit 3876d2d822
3 changed files with 22 additions and 1 deletions
+15
View File
@@ -93,6 +93,20 @@ static void testBothClipClampsBottom() {
CHECK(tb.y == 2);
}
// --- Narrow client: box width clamped ----------------------------------------
// When the client is narrower than the box's natural width, the box is shrunk to fit and
// the result satisfies x >= margin AND x + width <= clientW - margin.
// Natural boxW = 80+12 = 92. Narrow client = 60. maxBoxW = 60-4 = 56.
// Clamped boxW = 56. x = 2 + (108-56)/2 ... centred but clamped to [2, 60-2-56] = [2, 2].
static void testNarrowClientBoxClamped() {
const TooltipSpec spec{}; // margin = 2
const TooltipBox tb = computeTooltip(2, 10, 108, 34, 80, 14, 60, 300, spec);
CHECK(!tb.empty());
CHECK(tb.x >= spec.margin);
CHECK(tb.x + tb.width <= 60 - spec.margin);
}
// --- Degenerate --------------------------------------------------------------
static void testDegenerateEmpty() {
@@ -113,6 +127,7 @@ int main() {
testClampLeft();
testFlipAbove();
testBothClipClampsBottom();
testNarrowClientBoxClamped();
testDegenerateEmpty();
if (g_fail == 0) std::printf("tooltip: all tests passed\n");