Closed FrankvdStam closed 4 years ago
Looks like other windows work fine, only the window I moved is affected.
This looks like a problem with the Emscripten port. I had to find a way to calculate the mouse position in the "terminal" based on the mouse position in the browser. To do this, I assumed a fixed font size is used in the browser. The relevant code is here:
and later:
I knew this is a "hacky" way, and it won't always work, but I couldn't figure out a way to get the actual character size for the current browser.
I believe this should not happen when used in the terminal. As for the browser - suggestions are welcome.
It's a scaling issue - if you move the window back to the top left corner, the cursor is back in the correct place. Move it down and you can see it desyncing from the cursor position. Move it back up and you see it matching up again.
Also notice how only height is affected; if you move the window right instead of down, the positions don't desyc.
I bet the character height is slightly off.
I bet the character height is slightly off.
That is correct. The question is how to determine the character height/width correctly. I also tried Firefox 71.0 (64-bit) on Ubuntu 18.04 and I don't observe a vertical offset. However, I do observe a horizontal offset. Maybe the character spacing is not a function of just the browser, but also some other factors.
Here is a Stack Overflow thread that might turn out to be useful in solving this problem.
I see someone posted a solution, converting every letter to an element seems excessive. Don't know what this will do to performance in the long run/if you have a lot of text. Calculating the position scales better. I'll see if I can find a better solution tomorrow.
Can't get build to work. Will have to postpone.
@FrankvdStam I believe I found the right way to calculate the character size with 789c3a6. I create a single-character <span>
element and get it's size with getBoundingClientRect()
I still can't build and therefore can't test. Let me know when you have this live somewhere?
It's live at imtui.ggerganov.com
Yes, works properly now. Well done. Also works on Firefox android.
After moving a window, the cursor selects buttons slightly higher then were the cursor is drawn. I'm talking about moving an ImTui window, not the whole browser window. Having the issue on Firefox 71.0 (64-bit).