GuiTooltip() - Fix tooltip height for multiple lines and show tooltip over box in case out of screen (#521)

* correctly wrap multiline tooltips and show them over controlRec in case the tooltip is too low.

* include .y that was ommited

* fix size of padding to account for multiple lines
This commit is contained in:
Foivos
2026-02-17 15:58:44 +02:00
committed by GitHub
parent 4a7c6e17d5
commit 628a4b2bfd

View File

@ -5424,13 +5424,18 @@ static void GuiTooltip(Rectangle controlRec)
if ((controlRec.x + textSize.x + 16) > GetScreenWidth()) controlRec.x -= (textSize.x + 16 - controlRec.width); if ((controlRec.x + textSize.x + 16) > GetScreenWidth()) controlRec.x -= (textSize.x + 16 - controlRec.width);
GuiPanel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.0f }, NULL); int numberOfLines;
GetTextLines(guiTooltipPtr, &numberOfLines);
if ((controlRec.y + controlRec.height + textSize.y + 4 + 8 * numberOfLines) > GetScreenHeight())
controlRec.y -= (controlRec.height + textSize.y + 4 + 8 * numberOfLines);
GuiPanel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, textSize.y + 8.0f * numberOfLines }, NULL);
int textPadding = GuiGetStyle(LABEL, TEXT_PADDING); int textPadding = GuiGetStyle(LABEL, TEXT_PADDING);
int textAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT); int textAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
GuiSetStyle(LABEL, TEXT_PADDING, 0); GuiSetStyle(LABEL, TEXT_PADDING, 0);
GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
GuiLabel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.0f }, guiTooltipPtr); GuiLabel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, textSize.y + 8.0f * numberOfLines }, guiTooltipPtr);
GuiSetStyle(LABEL, TEXT_ALIGNMENT, textAlignment); GuiSetStyle(LABEL, TEXT_ALIGNMENT, textAlignment);
GuiSetStyle(LABEL, TEXT_PADDING, textPadding); GuiSetStyle(LABEL, TEXT_PADDING, textPadding);
} }