mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5048
5048: fix tooltips rendering when they shouldn't, fixes #5035 r=def- a=edg-l <!-- What is the motivation for the changes of this pull request --> fixes #5035 ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Edgar Luque <git@edgarluque.com>
This commit is contained in:
commit
7c83bf85ec
|
@ -33,13 +33,17 @@ void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char
|
|||
const auto result = m_Tooltips.emplace(ID, CTooltip{
|
||||
*pNearRect,
|
||||
pText,
|
||||
WidthHint});
|
||||
WidthHint,
|
||||
false});
|
||||
CTooltip &Tooltip = result.first->second;
|
||||
|
||||
if(!result.second)
|
||||
{
|
||||
Tooltip.m_Rect = *pNearRect; // update in case of window resize
|
||||
}
|
||||
|
||||
Tooltip.m_OnScreen = true;
|
||||
|
||||
if(UI()->MouseInside(&Tooltip.m_Rect))
|
||||
{
|
||||
SetActiveTooltip(Tooltip);
|
||||
|
@ -54,10 +58,14 @@ void CTooltips::OnRender()
|
|||
|
||||
if(!UI()->MouseInside(&Tooltip.m_Rect))
|
||||
{
|
||||
Tooltip.m_OnScreen = false;
|
||||
ClearActiveTooltip();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Tooltip.m_OnScreen)
|
||||
return;
|
||||
|
||||
// Delay tooltip until 1 second passed.
|
||||
if(HoverTime > time_get() - time_freq())
|
||||
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);
|
||||
Rect.Margin(2.0f, &Rect);
|
||||
UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT);
|
||||
Tooltip.m_OnScreen = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ struct CTooltip
|
|||
CUIRect m_Rect;
|
||||
const char *m_pText;
|
||||
float m_WidthHint;
|
||||
bool m_OnScreen; // used to know if the tooltip should be rendered.
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue