From 13775754620609dc98f8b1e6e594173f2b5945f2 Mon Sep 17 00:00:00 2001 From: MrTheShy <49885496+MrTheShy@users.noreply.github.com> Date: Fri, 6 Mar 2026 05:25:47 +0100 Subject: [PATCH] Use smallest-area tiebreaker for mouse click hit-testing too Same overlap fix applied to handleMouseClick: when multiple controls contain the click point, prefer the one with the smallest bounding area instead of the one with the largest left-edge X. This is more robust for any layout (vertical menus, grids, overlapping panels) and matches the hover path logic. Those changes were initially made in order to fix the teleport ui for the mouse but broke every other well working ui. --- Minecraft.Client/Common/UI/UIScene.cpp | 13 ++++++------- Minecraft.Client/Common/UI/UIScene.h | 5 ++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Minecraft.Client/Common/UI/UIScene.cpp b/Minecraft.Client/Common/UI/UIScene.cpp index 9fb67d9e4..dc5c9d8fc 100644 --- a/Minecraft.Client/Common/UI/UIScene.cpp +++ b/Minecraft.Client/Common/UI/UIScene.cpp @@ -469,12 +469,10 @@ bool UIScene::handleMouseClick(F32 x, F32 y) vector *controls = GetControls(); if (!controls) return false; - // Flash may report overlapping bounds for side-by-side controls (e.g. - // TextInputs with full 630px width in debug scenes). Among all controls - // that contain the click point, pick the one whose left edge (cx) is - // closest to the click X — i.e. largest cx that is still <= x. + // Hit-test controls and pick the smallest-area match to handle + // overlapping Flash bounds correctly without sacrificing precision. int bestId = -1; - S32 bestCx = -1; + S32 bestArea = INT_MAX; UIControl *bestCtrl = NULL; for (size_t i = 0; i < controls->size(); ++i) @@ -501,9 +499,10 @@ bool UIScene::handleMouseClick(F32 x, F32 y) if (x >= cx && x <= cx + cw && y >= cy && y <= cy + ch) { - if (cx > bestCx) + S32 area = cw * ch; + if (area < bestArea) { - bestCx = cx; + bestArea = area; bestId = ctrl->getId(); bestCtrl = ctrl; } diff --git a/Minecraft.Client/Common/UI/UIScene.h b/Minecraft.Client/Common/UI/UIScene.h index 416e9374b..df2bc840d 100644 --- a/Minecraft.Client/Common/UI/UIScene.h +++ b/Minecraft.Client/Common/UI/UIScene.h @@ -184,9 +184,8 @@ public: virtual UIControl* GetMainPanel(); #ifdef _WINDOWS64 - // Mouse click dispatch. Default implementation hit-tests C++ controls with - // "best match" logic (largest left-edge X) to handle overlapping Flash bounds, - // then calls the virtual handlePress. Override for custom behaviour (e.g. crafting). + // Mouse click dispatch. Hit-tests C++ controls and picks the smallest-area + // match, then calls handlePress. Override for custom behaviour (e.g. crafting). virtual bool handleMouseClick(F32 x, F32 y); #endif