I’ve been working on some unicode-aware gui for the OpenFrameworks :
Here is what I got thus fur:
unicode textboxes for inputing multiline autoformated unicode text in mac+ pc
drop down semitrasparent menus
lists for inputing values and auto-refresh dropdown menus
copy paste dropdown menu (this is released at my github)
and a calendar that is able to do stuff like goTo(40,“12/2/2014”) that means go to 40 days from that day or to the past etc
also many other useful calendar stuff like get Howmany days a month has etc.
here is an example of the gui in action:
so in ascci a char = a character
in utf8 a character can be two chars or bytes etc
say you have a unicode text: “κείμενο”
it’s not an array of 8 chars but 16+
so let’s say you place your cursor at the end and you pressbackspace
if you only remove one char you will mess up your string , so you need to understand how many bytes / numbers are used to represent that string you are seeing
I’ve tried some ideas I had, but I couldn’t find a way to be 100% accurate
so right now I hard code stuff,
Is there a smart way to do this?
I mean what if you put a Chinese char in the text how do I know when my actual character begins in a utf8 string and where it begins so that I can
place the cursor in the correct place in the array
remove the correct number of bytes ??
here is a video of the problem in action
the bug occurs at the end of the video where I place a “Π” that messed up the hard coded algorithm I used
finally got around to create two examples for ofOpenFile function:
if anybody wants to use this:
I’m really really interested on that addon!! Maybe I could give you a hand on that issue.
I actually had to deal with something similar last week because my program was crashing when emojis appeared in a UTF8 string. I didn’t know anything about UTF8 and all so I had to read a lot to find my way. I can reccomend you too good readings:
A very good introduction to the topic:
And a precise answer to how long is each glyph:
I uploaded my sketch (a bit dirty) that I used to understand a bit on the topic. Maybe it will help you to understand some things… It is very simple… just printing values to understand the size of a string and all…
One more thing here. I’m aware that @bakercp is working on the “next level” text tools for OF. I don’t know what is the state of his work but I’m totally confident that he is The Guru about this topic (and everything else;)
yes bakercp is the utf8 guru indeed hopefully one day OF is going to be uft8 aware !
in the meanwhile
I have modified the ofsystemUtils OF files so that OF ofSystemAlert and textinut dialogs are working with non english characters sutils.zip (9.0 KB)
thanks for the
Example-parse_UTF8_string link I am going to study this
it might help me finish what I’ve started , it seems like a good place to start!!
maybe you can take a look at my utf8 ofCopyPaste example
The CopyPaste menu will be part of the textbox it’s unicode aware and works great both on windows and mac
my testing with utf8 strings for the past few months has been bug-free - you can try it as well
I’ve made a couple of textboxes thus far…
some using fontStash auto resize draw multiline and others using a heavily modified ofxTextInputField class… but you need to modify OF, and none of them is 100% perfect thus far I will let you know if I have a breakthrough!
Hey friends – getting really close to dropping the latest utf8 aware ofxFont … I’m rushing to get it done so hopefully we can document it in time for ofBook. I’ll keep you posted … regarding clipboard support, this PR has been sitting around for a long while:
I’ve extended a few objective-c classes inside system Utils and overloaded some of their functions so that they can be used in a different way. (attached above openGl)
As is - the core is modified since SystemUtils.cpp is the only place that we are able to call windows or obj-functions, but it’s possible to just move everything to a single addon, we will see. I might not have a choice anyway because I need some values from the main window for the mac vrsion., like knowing if it’s focused or not. and I can’t do it as OF is structured right now. but this is solvable if I move the addon on a higher level , or use pointers etc.
surely the more advanced OF folks can help with these issues if we decide to move this to the core.
I have everything solved inside my head J, I just need time to sit down and write it,
The positive is that it seems that the text box is working with both Glut and GLFW.
I am making the object by default multiline but a single line version of it can be called using .setMultiline(false)
Also Password mode is available. and ofcourse a scrolbar.