diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-26 19:00:43 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-26 19:00:43 +0300 |
commit | 2e401c3cfa4462f83e280bd9820e0f41c734bbbc (patch) | |
tree | 3acb929643ff33c6bf9c108b970d3d89196188c8 /src/ui | |
parent | 4d4829ea8bc7e5819a3577bae1b87e545db85330 (diff) |
Compute popup menu bounds in points
Display bounds and the window rectangle are handled in points, so
determine if the menu fits inside its root in points, too.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/util.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 4ab086fe..72a973a6 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1034,11 +1034,18 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1034 | } | 1034 | } |
1035 | iRect winRect; | 1035 | iRect winRect; |
1036 | SDL_Window *sdlWin = get_Window()->win; | 1036 | SDL_Window *sdlWin = get_Window()->win; |
1037 | SDL_GetWindowPosition(sdlWin, &winRect.pos.x, &winRect.pos.y); | 1037 | const float pixelRatio = get_Window()->pixelRatio; |
1038 | SDL_GetWindowSize(sdlWin, &winRect.size.x, &winRect.size.y); | 1038 | iInt2 winPos; |
1039 | SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y); | ||
1040 | winRect = rootRect; | ||
1041 | winRect.pos.x /= pixelRatio; | ||
1042 | winRect.pos.y /= pixelRatio; | ||
1043 | winRect.size.x /= pixelRatio; | ||
1044 | winRect.size.y /= pixelRatio; | ||
1045 | addv_I2(&winRect.pos, winPos); | ||
1039 | iRect visibleWinRect = intersect_Rect(winRect, displayRect); | 1046 | iRect visibleWinRect = intersect_Rect(winRect, displayRect); |
1040 | /* Only use a popup window if the menu can't fit inside the main window. */ | 1047 | /* Only use a popup window if the menu can't fit inside the main window. */ |
1041 | if (height_Widget(d) > visibleWinRect.size.y && isUsingMenuPopupWindows_()) { | 1048 | if (height_Widget(d) * pixelRatio > visibleWinRect.size.y && isUsingMenuPopupWindows_()) { |
1042 | if (postCommands) { | 1049 | if (postCommands) { |
1043 | postCommand_Widget(d, "menu.opened"); | 1050 | postCommand_Widget(d, "menu.opened"); |
1044 | } | 1051 | } |
@@ -1050,7 +1057,6 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1050 | removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ | 1057 | removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ |
1051 | iInt2 winPos; | 1058 | iInt2 winPos; |
1052 | SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y); | 1059 | SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y); |
1053 | const float pixelRatio = get_Window()->pixelRatio; | ||
1054 | iInt2 menuPos = add_I2(winPos, | 1060 | iInt2 menuPos = add_I2(winPos, |
1055 | divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); | 1061 | divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); |
1056 | /* Check display bounds. */ { | 1062 | /* Check display bounds. */ { |