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

Accurate postion of a widget #3817

Closed
miscvariables opened this issue Feb 17, 2021 · 2 comments
Closed

Accurate postion of a widget #3817

miscvariables opened this issue Feb 17, 2021 · 2 comments

Comments

@miscvariables
Copy link

miscvariables commented Feb 17, 2021

Version: 1.79
Branch: master
OpenGL ES/Android, Native Activity

Operating System: Android

Thank you for the great UI library. I am working on a portable mobile GUI. I have done IME input, inertia scrolling etc, it working perfectly, just like a native app. Except one thing. We all know on mobile screen, either Android or iOS, when app receives input, a soft keyboard will popup, and the ImGui window should resize and scroll the InputText widget to just above the IME region. I need the accurate position of the widget of InputText to adjust the window. I used ImGui::GetFrameHeight()*0.5 for approximate location, the effect is not consistent. I attached 3 captures for indication. enter "Android" in an InputText, when IME popups, resize and scroll the window, under scrolled, exact scrolled, over scrolled.

I read the imgui.cpp and imgui_internal.h and found there is no such a way to get the position of a InputText widget. As I know it's "Immediate Mode GUI", you keep minimal states of widget, and calculate ImRect frame_bb in InputTextEx() and doesn't save it after that, so I can only get the temporary saved state in window->DC using GetItemRectMin() etc. But the states are only available after create the widget. Is it the fact?

I found you saved a g.NavId for long term access, Is it possible to add the position and size(just like frame_bb) of the Active widget. Thanks

image

@miscvariables
Copy link
Author

Update myself.
The suggestion above is not a good solution, because you can't get correct position of multi-line input. After read InputTextEx throughout, I found there was a variable g.PlatformImePos, which is the cursor position in InputText. It's the perfect state for window adjustment. Happy open source!

@ocornut
Copy link
Owner

ocornut commented Feb 17, 2021

It’s an interesting problem, I suppose we would eventually aim to find a way to solve it more elegantly with an interaction between imgui and backends (eg backend notifying dear imgui of on screen keyboard, altering monitor/viewport work area, requesting to keep input source visible). We would probably also need to expose actual input cursor position to be able to handle edge cases of multi-line input frame being larger than available monitor/viewport real estate minus the on screen keyboard.

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

No branches or pull requests

2 participants