Skip to content

Specify position and pivot for OpenPopup #9379

Description

@tope99

Version/Branch of Dear ImGui:

Version 1.92.6, Branch: docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp

Compiler, OS:

Windows 11 + VS 2022

Full config/build information:

No response

Details:

My Issue/Question:

It would be nice to be able to set popup menu position and pivot upon calling OpenPopup (not at BeginPopup). For example to implement drop down menu button I can calculate the popup menu position to be aligned with the button rect and then show it at that location. OpenPopupEx seems to be storing the mouse cursor position in ImGuiPopupData but it doesn't allow to override it or to specify pivot which is important (when f.e. drop down button is on the right side of the screen so the menu should be aligned with button's right edge).

Currently I am doing this to set the position:

ImGui::SetNextWindowPos(pos, ImGuiCond_Always, pivot);
if (ImGui::BeginPopup(str_id))
{
    //no need to submit menu items here, just for setting the menu position
    ImGui::GetCurrentWindow()->LastFrameActive = -1; //recalc window size in next invocation when items are submitted
    ImGui::EndPopup();
}

But it feels hackish.

It would be even more helpful when ImGui calculates the menu position itself when certain flag in OpenPopup is set. We could have PopupPositionPolicy_ItemOverlap where the popup menu overlaps the drop down button as it is common in mobile apps and PopupPositionPolicy_ItemSide to align the popup menu similarly how the combo popup is aligned.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions