Attempt at making a UI Library
Hi there, I am making a UI Library as I had some free timeI've added a button which functions
Then I tried to add a Text Box, for which I needed to add a blinking cursor
The cursor animates properly but the problem is that the position of the cursor is not correct
I have not changed the Size, Font, Alignment or anything of the text but still the cursor renders far ahead of where it's supposed to
This is the code to render the cursor
line(x + textWidth(val), y + 2, x + textWidth(val), y + textAscent() + 2);I've heard somewhere that padding is already included in the textWidth function... due to which i have not added +2 to the x and w value, val is a string that's updated everytime the user presses a key on the keyboard
The y values work ok for now... There are no error messages too
I've tried looking online but none of the solutions work for me
Having a quick look, my opinion is Processing's text facilties need a bit of love, as you can see here and here (and the commented code as well). The
F2XDrenderer seems to handle this a bit better;Looking at the images, there might be some special unicode characters not properly displayed and the font is variable with.
If you're willing to compromise with a basic proof of concept you could get something off the ground by sticking to a monospaced font such as Courier New: it produces more predictable results (and using
FX2Dhelps):Another option might be using JavaFX mostly to manually handle text then rendering those text components into Processing's
FX2DCanvas. (This may be more verbose.)