From 144a8877bb43fce3cabfe4416b09400b1889f5a1 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 26 Sep 2021 19:21:45 +0300 Subject: Popup menus are positioned on selected item --- src/ui/util.c | 10 +++++++++- src/ui/window.c | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/util.c b/src/ui/util.c index 72a973a6..adee2ee5 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1023,6 +1023,14 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); arrange_Widget(d); /* need to know the height */ + /* A vertical offset determined by a possible selected label in the menu. */ { + iConstForEach(ObjectList, child, children_Widget(d)) { + const iWidget *item = constAs_Widget(child.object); + if (flags_Widget(item) & selected_WidgetFlag) { + windowCoord.y -= item->rect.pos.y; + } + } + } #if defined (LAGRANGE_ENABLE_POPUP_MENUS) /* Determine total display bounds where the popup may appear. */ iRect displayRect = zero_Rect(); @@ -1045,7 +1053,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { addv_I2(&winRect.pos, winPos); iRect visibleWinRect = intersect_Rect(winRect, displayRect); /* Only use a popup window if the menu can't fit inside the main window. */ - if (height_Widget(d) * pixelRatio > visibleWinRect.size.y && isUsingMenuPopupWindows_()) { + if (height_Widget(d) / pixelRatio > visibleWinRect.size.y && isUsingMenuPopupWindows_()) { if (postCommands) { postCommand_Widget(d, "menu.opened"); } diff --git a/src/ui/window.c b/src/ui/window.c index bdac441a..164c2478 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1659,6 +1659,7 @@ iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) { win->keyRoot = root; root->widget = rootWidget; root->window = win; + rootWidget->rect.pos = zero_I2(); setRoot_Widget(rootWidget, root); setForceSoftwareRender_App(oldSw); stop_PerfTimer(newPopup_Window); -- cgit v1.2.3