fix tooltips rendering when they shouldn't, fixes #5035

This commit is contained in:
Edgar 2022-04-30 10:05:28 +02:00
parent 787224a2a7
commit 4b25f8d63e
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
2 changed files with 11 additions and 1 deletions

View file

@ -33,13 +33,17 @@ void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char
const auto result = m_Tooltips.emplace(ID, CTooltip{ const auto result = m_Tooltips.emplace(ID, CTooltip{
*pNearRect, *pNearRect,
pText, pText,
WidthHint}); WidthHint,
false});
CTooltip &Tooltip = result.first->second; CTooltip &Tooltip = result.first->second;
if(!result.second) if(!result.second)
{ {
Tooltip.m_Rect = *pNearRect; // update in case of window resize Tooltip.m_Rect = *pNearRect; // update in case of window resize
} }
Tooltip.m_OnScreen = true;
if(UI()->MouseInside(&Tooltip.m_Rect)) if(UI()->MouseInside(&Tooltip.m_Rect))
{ {
SetActiveTooltip(Tooltip); SetActiveTooltip(Tooltip);
@ -54,10 +58,14 @@ void CTooltips::OnRender()
if(!UI()->MouseInside(&Tooltip.m_Rect)) if(!UI()->MouseInside(&Tooltip.m_Rect))
{ {
Tooltip.m_OnScreen = false;
ClearActiveTooltip(); ClearActiveTooltip();
return; return;
} }
if(!Tooltip.m_OnScreen)
return;
// Delay tooltip until 1 second passed. // Delay tooltip until 1 second passed.
if(HoverTime > time_get() - time_freq()) if(HoverTime > time_get() - time_freq())
return; return;
@ -100,5 +108,6 @@ void CTooltips::OnRender()
RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), CUI::CORNER_ALL, 5.0f);
Rect.Margin(2.0f, &Rect); Rect.Margin(2.0f, &Rect);
UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT); UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT);
Tooltip.m_OnScreen = false;
} }
} }

View file

@ -13,6 +13,7 @@ struct CTooltip
CUIRect m_Rect; CUIRect m_Rect;
const char *m_pText; const char *m_pText;
float m_WidthHint; float m_WidthHint;
bool m_OnScreen; // used to know if the tooltip should be rendered.
}; };
/** /**