mirror of
https://github.com/minetest/minetest.git
synced 2025-03-25 19:52:35 +01:00
Formspec: Move tooltip above cursor when lacking space (#15470)
This commit is contained in:
@ -3610,10 +3610,25 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text,
|
|||||||
// Calculate and set the tooltip position
|
// Calculate and set the tooltip position
|
||||||
s32 tooltip_x = m_pointer.X + tooltip_offset_x;
|
s32 tooltip_x = m_pointer.X + tooltip_offset_x;
|
||||||
s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
|
s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
|
||||||
if (tooltip_x + tooltip_width > (s32)screenSize.X)
|
// Bottom/Left limited positions (if the tooltip is too far out)
|
||||||
tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
|
s32 tooltip_x_alt = (s32)screenSize.X - tooltip_width - m_btn_height;
|
||||||
if (tooltip_y + tooltip_height > (s32)screenSize.Y)
|
s32 tooltip_y_alt = (s32)screenSize.Y - tooltip_height - m_btn_height;
|
||||||
tooltip_y = (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(
|
m_tooltip_element->setRelativePosition(
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
|
Reference in New Issue
Block a user