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

Offset tooltip and drag/drop position for touch based input #8036

Closed
catlowlevel opened this issue Oct 2, 2024 · 5 comments
Closed

Offset tooltip and drag/drop position for touch based input #8036

catlowlevel opened this issue Oct 2, 2024 · 5 comments
Labels

Comments

@catlowlevel
Copy link

Version/Branch of Dear ImGui:

docking

Back-ends:

imgui_impl_android.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

ndk, Android

Full config/build information:

No response

Details:

because the content of the tooltip is kind of hard to see if the input is touch based (blocked by finger), i would like to offset the tooltip position.
right now im using this code

void ImGuiEx::HelpMarker(const char *desc)
{
    ImGui::TextDisabled("(?)");
    ImGuiIO &io = ImGui::GetIO();
    // offset the tooltip 
    if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip) && io.MouseSource == ImGuiMouseSource_TouchScreen)
    {
        ImVec2 pos = io.MousePos;
        pos.y -= ImGui::GetFontSize() * 2;
        ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 1.0f));
    }
    if (ImGui::BeginItemTooltip())
    {
        ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
        ImGui::TextUnformatted(desc);
        ImGui::PopTextWrapPos();
        ImGui::EndTooltip();
    }
}

is this the correct way? im also using this with BeginDragDropSource, however, the drop target location remain in the touch position, which again is kind of blocked by the finger, so is it possible to also offset the BeginDragDropTarget accept position?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Oct 2, 2024

is this the correct way?

it is not incorrect, but I think the issue you are pointing at would be best corrected in the library itself and by default, so we should investigate that.

im also using this with BeginDragDropSource, however, the drop target location remain in the touch position

You could technically call SetNextWindowPos() before BeginDragDropSource(). But ditto I think it should be done in the library.

@ocornut
Copy link
Owner

ocornut commented Oct 2, 2024

It's not as simple as expected for a surprising reason: using a position pivot that is not (0,0) make it visible and problematic when a tooltip change from one another, e.g. color preview tooltip vs color drag tooltip. I'll need more time to fix it nicely.

To clarify: if the tooltip size changes then it affects the position using pivot, so there is a visible glitches where you see the new tooltip in one position then another the next frame.

@ocornut
Copy link
Owner

ocornut commented Oct 3, 2024

I have pushed f057541, 014b722 and 5109a77.
The second one aim to fix the issue visible when relying on pivot.
The third one moves the tooltip (and use pivot) for touch- that code is quite awkward right now as generally tooltip positioning is in need of a bit of a refactor. But I'm happy to add more to the fix as that'll be useful for the refactor.

Also amended test: ocornut/imgui_test_engine@5f61301

Let me know if that works for you!

@ocornut ocornut closed this as completed Oct 3, 2024
@ocornut ocornut reopened this Oct 14, 2024
@ocornut
Copy link
Owner

ocornut commented Oct 14, 2024

This broke positioning of tooltip when using keyboard/gamepad navigation.

ocornut added a commit that referenced this issue Oct 14, 2024
…epad navigation (1.91.3 regression). (#8036)

Regression in 1.91.3 commit 5109a77.
ocornut added a commit that referenced this issue Oct 14, 2024
…epad navigation (1.91.3 regression). (#8036)

Regression in 1.91.3 commit 5109a77.
@ocornut
Copy link
Owner

ocornut commented Oct 14, 2024

Fixed with 50de550

@ocornut ocornut closed this as completed Oct 14, 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