mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Support rendering tooltips with multiple lines of text
Render tooltip text correctly with multiple lines when the maximum tooltip width is limited. Add missing padding when rendering multi-line tooltip. Update doxygen documentation.
This commit is contained in:
parent
20032b5a24
commit
ed09bba45a
|
@ -76,19 +76,10 @@ void CTooltips::OnRender()
|
|||
constexpr float Margin = 5.0f;
|
||||
constexpr float Padding = 5.0f;
|
||||
|
||||
const STextBoundingBox BoundingBox = TextRender()->TextBoundingBox(FontSize, Tooltip.m_pText, -1, Tooltip.m_WidthHint);
|
||||
CUIRect Rect;
|
||||
if(Tooltip.m_WidthHint < 0.0f)
|
||||
{
|
||||
const STextBoundingBox BoundingBox = TextRender()->TextBoundingBox(FontSize, Tooltip.m_pText);
|
||||
Rect.w = BoundingBox.m_W + 2 * Padding;
|
||||
Rect.h = BoundingBox.m_H + 2 * Padding;
|
||||
}
|
||||
else
|
||||
{
|
||||
const STextBoundingBox BoundingBox = TextRender()->TextBoundingBox(FontSize, Tooltip.m_pText, -1, Tooltip.m_WidthHint);
|
||||
Rect.w = Tooltip.m_WidthHint;
|
||||
Rect.h = BoundingBox.m_H;
|
||||
}
|
||||
Rect.w = BoundingBox.m_W + 2 * Padding;
|
||||
Rect.h = BoundingBox.m_H + 2 * Padding;
|
||||
|
||||
const CUIRect *pScreen = UI()->Screen();
|
||||
Rect.w = minimum(Rect.w, pScreen->w - 2 * Margin);
|
||||
|
@ -121,7 +112,9 @@ void CTooltips::OnRender()
|
|||
|
||||
Rect.Draw(ColorRGBA(0.2f, 0.2f, 0.2f, 0.8f), IGraphics::CORNER_ALL, Padding);
|
||||
Rect.Margin(Padding, &Rect);
|
||||
UI()->DoLabel(&Rect, Tooltip.m_pText, FontSize, TEXTALIGN_ML);
|
||||
SLabelProperties Props;
|
||||
Props.m_MaxWidth = Tooltip.m_WidthHint;
|
||||
UI()->DoLabel(&Rect, Tooltip.m_pText, FontSize, TEXTALIGN_ML, Props);
|
||||
Tooltip.m_OnScreen = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,10 @@ public:
|
|||
*
|
||||
* On the first call to this function, the data passed is cached, afterwards the calls are used to detect if the tooltip should be activated.
|
||||
*
|
||||
* For now only works correctly with single line tooltips, since Text width calculation gets broken when there are multiple lines.
|
||||
*
|
||||
* @param pID The ID of the tooltip. Usually a reference to some g_Config value.
|
||||
* @param pNearTo Place the tooltip near this rect.
|
||||
* @param pText The text to display in the tooltip
|
||||
* @param pNearRect Place the tooltip near this rect.
|
||||
* @param pText The text to display in the tooltip.
|
||||
* @param WidthHint The maximum width of the tooltip, or -1.0f for unlimited.
|
||||
*/
|
||||
void DoToolTip(const void *pID, const CUIRect *pNearRect, const char *pText, float WidthHint = -1.0f);
|
||||
|
||||
|
|
Loading…
Reference in a new issue