Formspec: Move tooltip above cursor when lacking space (#15470)

This commit is contained in:
SmallJoker 2024-12-06 21:59:51 +01:00 committed by GitHub
parent 88c845166c
commit 5a8412dd23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3610,10 +3610,25 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text,
// Calculate and set the tooltip position
s32 tooltip_x = m_pointer.X + tooltip_offset_x;
s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
if (tooltip_x + tooltip_width > (s32)screenSize.X)
tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
if (tooltip_y + tooltip_height > (s32)screenSize.Y)
tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
// Bottom/Left limited positions (if the tooltip is too far out)
s32 tooltip_x_alt = (s32)screenSize.X - tooltip_width - m_btn_height;
s32 tooltip_y_alt = (s32)screenSize.Y - tooltip_height - m_btn_height;
int collision = (tooltip_x_alt < tooltip_x) + 2 * (tooltip_y_alt < tooltip_y);
switch (collision) {
case 1: // x
tooltip_x = tooltip_x_alt;
break;
case 2: // y
tooltip_y = tooltip_y_alt;
break;
case 3: // both
tooltip_x = tooltip_x_alt;
tooltip_y = (s32)screenSize.Y - 2 * tooltip_height - m_btn_height;
break;
default: // OK
break;
}
m_tooltip_element->setRelativePosition(
core::rect<s32>(