-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
TouchExtraPadding works fine but there's no way to distinguish between mouse and touch input #2334
Comments
Hello @ifarbod and thanks for your effort developping this post. The problem is that I haven't explored touch controls properly, and we don't even have many example associated to touch devices. My suggestion short-term would be to implement your idea in (3) Down the line, I think we will implement (2) in core imgui. I already have a plan to rework the ImGuiIO api toward a more event-driven approach, something like https://gist.github.com/ocornut/8417344f3506790304742b07887adf9f. It's actually not much work and has the advantage that old back-ends will still work so that removes a lot of the friction toward implementing something like this. I can see this happening in the following few months. So we can perfectly add explicitely named Mouse and Touch functions. Both will probably lead to setting io.MousePos with extra info/flags on the side that will alter behavior. (4) Isn't really valid, not because the of platform The issue is mostly that while we are at it, we should handle touch better, namely e.g. handle scrolling with dual-finger gestures and that will add more design work. And as you mention stylus events, how would they fit in there? Is a stylus emulating a mouse the ideal? If you are able to explore better support for touch (incl. scrolling with dual finger) and provide ImGuiIo API suggestions and/or possible implementation, that would help moving this topic ahead faster. |
Hi @ocornut and thanks for your response!
Same, until this was brought to my attention. I haven't looked thoroughly at the Allegro5/Marmalade examples yet, do they handle touch events better than the SDL2 backend? I'm unfamiliar with them and at a quick peek, Allegro5 doesn't have anything related to touchscreens, and Marmalade has them in
Right, I'm already doing this as we speak, it's seems like a reasonable workaround for now.
Nice! This looks much more extensible than the current
As far as the examples are concerned, none of them set
Agreed, is proper touch support more of a long-term goal in Dear ImGui?
In Android's case, styli are handled like normal touch events, with a few exceptions. getToolType -> TOOL_TYPE_STYLUS (or TOOL_TYPE_ERASER)
Once they make contact with the screen, they're reported as the usual touch events ( getSources -> SOURCE_STYLUS Bit OR'd with SOURCE_TOUCHSCREEN - Probably as a way of compatibility method for apps that don't need to handle it differently. A similiarity, or difference would be buttons found on stylus pens. Most stylus pens I've seen have one button (e.g. S-Pen on Note 8/9), some have two. The secondary button however, same as above, Android docs mention that it should invoke a secondary action, this button was reported as BUTTON_TERTIARY in older Android versions, which is equal to a middle mouse click. Popular apps like Google Chrome handle it the same. e.g. pressing it on a tab would close it. Maybe drawing apps make a more specialized use of them. Stylus pens are also capable of reporting other features such as pressure, tilt, orientation, and distance. But I think that's out of scope for Dear ImGui. A thing worth mentioning here is that there were old phones capable of reporting finger hover events much like a stylus pen, namely, the Galaxy S4 from 2013. But the newer Samsung phones dropped this feature. SDL2 itself doesn't support stylus events separately, I've modified their Android shim and the event handler logic to accommodate for this. I'm also thinking of doing a Dear ImGui backend with something much lightweight than SDL2 for mobile phones, possibly using GLFM since most of the required input APIs are exposed to Android NDK, or extracting parts of my own game engine for this. Most apps and games get away with handling them same as touch events, SDL also has a flag named Since Dear ImGui is targeted more towards content creators and power users, I think this would largely benefit drawing apps and games alike, as most palm rejection methods on Android uses
Sure thing, I'll see what I can do, can the issue remain open for the time being? :) |
Hi If it can be interesting, I've recently implemented a version WebGL via WebAssemply (emscripten) of my project, usable by tablets and smartphones, that uses touchscreen and ImGui (of course). Actually I used just a workaround (like described by @ifarbod) to "fool" ImGui: void emsMDeviceClass::imGuiUpdateTouch()
{
ImGuiIO& io = ImGui::GetIO();
const ImVec2 mouse_pos_backup = io.MousePos;
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
io.MouseHoveredViewport = 0;
// Update buttons
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
{
// If a touch event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[i] = imguiJustTouched[i]; // Touch instead mouseButton
}
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
for (int n = 0; n < platform_io.Viewports.Size; n++)
{
ImGuiViewport* viewport = platform_io.Viewports[n];
GLFWwindow* window = (GLFWwindow*)viewport->PlatformHandle;
IM_ASSERT(window != NULL);
IM_ASSERT(platform_io.Viewports.Size == 1);
// if (focused) -> // Removed also "focus test", because I'm in EMSCRIPTEN
{
// double mouse_x, mouse_y;
// glfwGetCursorPos(window, &mouse_x, &mouse_y);
// instead to call it, I have saved touch coords from last event
io.MousePos = ImVec2((float)touchX + viewport->Pos.x, (float)touchY + viewport->Pos.y);
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) {
io.MouseDown[i] |= imguiJustTouched[i]; // Touch instead mouseButton
}
}
}
} It just replies the mouse coordinates with the touch ones ( ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
if(theApp->isTabletMode()) theApp->getEmsDevice().imGuiUpdateTouch();
ImGui::NewFrame(); The WebGL version is online here wglChAoS.P (if you want test it) I know: this is a workaround, as written, and is a function that override others (mouse) values just written, but I do not want modify ImGui code, that is in continue evolution. Thanks. |
@BrutPitt I've looked at your code, I think it's good enough for the time being, I personally had a similar idea, like yours, to use touch events given by the platform, and simulate mouse events at the end (e.g. dragging gesture producing proper
We should come up with proper touch support in Dear ImGui itself so we can ditch our current workarounds :D Off-topic: |
First of all there is to say that this method emulate the "touchs" over actual ImGui mouse management: it's not a touch event management. Said this, I thought a similar workaround would be quite simple to implement in ImGui (mostly without modifying the current behavior/functionality): Second. But I know that is necessary to consider everything globally and not for this particular example/use and for now I have tested this touch method only on SDL and GLFW with EMSCRIPTEN. However if @ocornut were possibilist on the method, and above all he has in the projects or desire to simulate touch events over actual mouse management, I can try to implement a working example. @ifarbod |
@ocornut Is there any chance of looking back at this again now that we have the new input API? :) |
i am looking to handle touch finger zoom in one of my canvases inside ImGui... i didn't see anything in ImGuiIO. Looks like I need WM_GESTURE and GID_ZOOM. |
I just pushed a16f99c + f070497 (and f33a0de, unrelated to this) to support that discrimination. However I didn't apply this to varying TouchPadding, as this would requires the backend to 100% support that discrimination. I am not sure what else there is to do and how much of @BrutPitt message #2334 (comment) is still valid. On my setup even though GLFW doesn't have explicit touch support, it does report touch screens as mouse events. If there is a missing component (Emscripten version, etc?) please to open a separate issue/PR and we'll address it. One that our Mouse vs TouchScreen discrimination for imgui_impl_glfw.cpp is for Windows only for now (see f070497). OK to happy other workaround in our GLFW backend until GLFW adds support. |
Version/Branch of Dear ImGui:
Back-end/Renderer/Compiler/OS
My Issue/Question:
So I've started running the official examples on mobile and encountered a small issue. As the title says, it's related solely to this API in the global style struct, I've set its value, it works as intended, but, I've noticed that touch input is just passed as mouse input in all of the official backends here (even the third party ones like SFML, openFrameworks, etc.) and the API itself doesn't have anything for passing touch events separately, this is understandable, my issue is actually, in the case of Android specifically, that in addition to the typical imprecise finger touches, there's more precise input events like styli (
MotionEvent.TOOL_TYPE_STYLUS
) and actual mice, unlike iOS (I might be wrong about this one). So I'd like to applyTouchExtraPadding
to my global style but have an exclusion for such cases.I've had a few ideas to work around this limitation; most of these are not the best ways nor optimal:
ImGuiIO
as Touch/TouchDown or something similiar, until better touch support is implemented. This is like an API breaking change (?)TouchExtraPadding
in touch events, and changing it back to 0 for stylus/mouse events. Unsure how would that work, and this is counter-inituitive IMO.And this is kind of against Dear ImGui's platform independency concept IMO.
Again, these aren't the best ways to do this.
I know that Dear ImGui is designed to be used primarily with a mouse and keyboard, however, since gamepad support got added not so long ago, I think this would also make for a great addition and would make the library much nicer to use on a phone.
This issue is mostly intended to create a discussion, I'm not sure if it has been mentioned here before, I looked in some of the issues here but couldn't find anything closely related (#1237 #2074 #1470 #443). Sorry if this came off vague, also, I've filled the template just in case and I'm willing to send PRs if needed :)
Screenshots/Video
Not that relevant and taken on Windows, but instead it demonstrates that it should work only on touch input, not mouse.
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: