| 55 | } |
| 56 | |
| 57 | void UpdatePosition(ScreenCoordsXY screenCoords) |
| 58 | { |
| 59 | int32_t screenWidth = ContextGetWidth(); |
| 60 | int32_t screenHeight = ContextGetHeight(); |
| 61 | screenCoords.x = std::clamp(screenCoords.x - (width / 2), 0, screenWidth - width); |
| 62 | |
| 63 | // TODO The cursor size will be relative to the window DPI. |
| 64 | // The amount to offset the y should be adjusted. |
| 65 | |
| 66 | const int32_t cursorHeight = 20; |
| 67 | const int32_t cursorMargin = 4; |
| 68 | const int32_t cursorOffset = cursorHeight + cursorMargin; |
| 69 | |
| 70 | const int32_t maxY = screenHeight - height; |
| 71 | |
| 72 | if (screenCoords.y + cursorOffset > maxY) |
| 73 | { |
| 74 | // Display the tooltip above the cursor if there is not enough space below. |
| 75 | screenCoords.y -= (height + cursorMargin); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | // Display the tooltip under the cursor if there is enough space below. |
| 80 | screenCoords.y += cursorOffset; |
| 81 | } |
| 82 | |
| 83 | screenCoords.y = std::clamp(screenCoords.y, cursorOffset, maxY); |
| 84 | |
| 85 | if (windowPos != screenCoords) |
| 86 | { |
| 87 | WindowSetPosition(*this, screenCoords); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void onOpen() override |
| 92 | { |
nothing calls this directly
no test coverage detected