Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: support Get/SetCursorScreenPosX/Y as well? #8086

Open
achabense opened this issue Oct 22, 2024 · 1 comment
Open

API: support Get/SetCursorScreenPosX/Y as well? #8086

achabense opened this issue Oct 22, 2024 · 1 comment
Labels

Comments

@achabense
Copy link

Version/Branch of Dear ImGui:

Version 1.91.2

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

No response

Details:

Sometimes I will do:

const float cursor_pos = GetCursorPosX();
...
SetCursorPosX(cursor_pos);

I hope to replace them with the screen-pos version, as they will go through unnecessary +- window-pos and window-scroll, and GetCursorPos is said "not the best friend". However, there are no SetCursorScreenPosX/Y counterparts, and it's inconvenient to use SetCursorScreenPos directly as I don't want to care about y-pos.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

static void example() {
    if (ImGui::Begin("Example", 0, ImGuiWindowFlags_NoSavedSettings)) {
        for (int i = 0; i < 10; ++i) {
            ImGui::Text("%d", i);
            ImGui::SameLine();

            // (Initially tried this when I tried to simplify a complex conditional Begin/EndGroup.)
            ImGui::PushID(i);
            const float cursor_pos = ImGui::GetCursorPosX(); // -> ImGui::GetCursorScreenPosX
            ImGui::Button("AAAAA");
            ImGui::SetCursorPosX(cursor_pos); // -> ImGui::SetCursorScreenPosX
            ImGui::Button("BBBBB");
            ImGui::PopID();
        }
    }
    ImGui::End();
}
@ocornut
Copy link
Owner

ocornut commented Oct 22, 2024

I have been reluctant to add them because in my experience, almost everytime people use the X/Y it is to add an offset, and therefore the GetCursorPosX() versions are perfectly fine.

However, it does confuse the user and in the name of trying to get people to do the mental switch I should probably add them.

@ocornut ocornut added the layout label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants