Fix tooltips being active behind popups and outside clipping rects

Ensure that tooltips are only activated when the associated UI element is currently the hot item. This prevents tooltips from being activated for UI elements that are currently not enabled due to them being behind a popup or outside of a clipping rect.
This commit is contained in:
Robert Müller 2023-05-29 11:22:33 +02:00
parent 57f1b1a8c6
commit bbe2430be9
2 changed files with 4 additions and 2 deletions

View file

@ -30,6 +30,7 @@ void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char
{
uintptr_t ID = reinterpret_cast<uintptr_t>(pID);
const auto result = m_Tooltips.emplace(ID, CTooltip{
pID,
*pNearRect,
pText,
WidthHint,
@ -44,7 +45,7 @@ void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char
Tooltip.m_OnScreen = true;
if(UI()->MouseInside(&Tooltip.m_Rect))
if(UI()->HotItem() == Tooltip.m_pID)
{
SetActiveTooltip(Tooltip);
}
@ -56,7 +57,7 @@ void CTooltips::OnRender()
{
CTooltip &Tooltip = m_ActiveTooltip.value();
if(!UI()->MouseInside(&Tooltip.m_Rect))
if(UI()->HotItem() != Tooltip.m_pID)
{
Tooltip.m_OnScreen = false;
ClearActiveTooltip();

View file

@ -11,6 +11,7 @@
struct CTooltip
{
const void *m_pID;
CUIRect m_Rect;
const char *m_pText;
float m_WidthHint;