{"id":55,"date":"2020-06-13T06:34:45","date_gmt":"2020-06-13T04:34:45","guid":{"rendered":"https:\/\/blogs.scummvm.org\/ar28\/?p=55"},"modified":"2022-04-15T06:37:00","modified_gmt":"2022-04-15T04:37:00","slug":"task2-begin-moving-gui-to-use-u32strings","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/ar28\/2020\/06\/13\/task2-begin-moving-gui-to-use-u32strings\/","title":{"rendered":"Task2.begin() &#8211; Moving GUI to use U32Strings!"},"content":{"rendered":"<p>This week, I got started with my new task &#8211; Moving GUI to U32Strings.<br \/>\nBefore I tell more about it, some miscellaneous things that happened this week:<\/p>\n<p>A team-member of ScummVM had previously worked on adding the achievements for some Wintermute games. He was very nice to offer me a game copy to test out the achievements for my task, but I had some steam credit so I thought there was finally a use for them! This way, I have bought my first ever steam game! I have run out of games &#8211; pre-2011 &#8211; that I can play on potato pc, so I never really bought anything from Steam. I have yet to try out the game, maybe sometime soon!<\/p>\n<p><!--more--><\/p>\n<p>While cleaning up the history and adding more code, I came across a merge conflict. Previously, I would just find a way around them, but this time I tried to solve it following step-by-step. This way, I learned how to solve merge conflicts! It was quite simple (at least for my small changes), and not as complicated as I thought it would be. I will try to solve more small issues with merge conflicts now.<\/p>\n<p>Another member of the community is testing out new things and making some improvement patches for my previous task &#8211; &#8220;RTL GUI&#8221;. He has written very clean and minimal code compared to the original code for Editables (widgets to type in) and Tabs. It was also a very great improvement over my code. It was very interesting to see how much a specific piece of code could be improved.<\/p>\n<div>\n<h3>The new task:<\/h3>\n<\/div>\n<div>So, how did I get started with my new task? In my last task, there were visual changes and behaviors I needed to change, and everything was pretty visible from the get-go. In this task, not so much. So, I decided to start small. Every widget in ScummVM has &#8220;Name&#8221; and &#8220;Label&#8221;, amongst other things.<\/div>\n<div><\/div>\n<div>Names are used internally, while labels are the text that widgets have attached which eventually get rendered. So, at the very base, I changed the label of ButtonWidgets from String to U32String. Apart from Labels, there are also many other things needed to be converted, but this seemed like a great place to start.<\/div>\n<div><\/div>\n<div>In ScummVM, there is a very neat little system and macros defined for translations. To use them in code, you would just do something like<br \/>\n_(&#8220;Message&#8221;)<br \/>\nand I get my translated piece of string (if any present) as type const char *. Because translations are used everywhere in the project, I can&#8217;t just change the return type here, because that will break too many things at 1 time and become a pain to solve each one without seeing any progress. So, after changing the label for one specific widget, I simply followed errors and converted the strings to U32Strings on a temporary basis like:<br \/>\n&#8230;, convertToU32(_(&#8220;Message&#8221;)), &#8230;<\/div>\n<div><\/div>\n<div>When all compilation errors got solved, I moved widget by widget. First, I covered all types of Buttons, then TextWidgets, Tabs, and so on.<\/div>\n<div><\/div>\n<div>To make them draw as U32String, I also changed the internal code to the appropriate type. At one further internal step, the drawing function only accepted Strings. So, there and many places, I used overloading to temporarily accept U32Strings as well as Strings &#8211; so all other unconverted widgets also draw properly.<\/div>\n<div><\/div>\n<div>After converting all widgets and using a bunch of temporary code, I gave my code a try. It worked near-perfectly for English but broke a lot of things in other languages, which was expected. Hebrew broke it nearly completely (as in the picture below).<\/div>\n<div><\/div>\n<div><a href=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56\" src=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/1.png\" alt=\"\" width=\"656\" height=\"438\" srcset=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/1.png 656w, https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/1-300x200.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><\/div>\n<div>\nOn Friday evening, I sat down to finally change translations to return U32Strings, which would mean that they affected the whole project. Because I had converted most widgets to U32Strings, I thought it was time. I hit compile and there were ~650 errors and 50 warnings! After widgets, I focused on converting tooltips from const char* to U32String. In code, everywhere a tooltip was not to be used, we used nullptr to mark a tooltip as absent. So, that also had to be changed. The issue with tooltips and my old temporary code made up half of the errors.<\/div>\n<div><\/div>\n<div>So, that day I spent clearing out all of them.<\/div>\n<div>\n<p>Firstly I decided to focus on the small issues with nullptr and my previous temp code. Finally, my shell-scripting classes came to see real use! I was a little rusty and unsure because I haven&#8217;t really used it in a project of this big size. But after some careful commits and checking, I was able to wipe these errors (~350-400) in a short period of time with minimal other side-effects.<\/p>\n<p>Afterward, I manually went through the remaining to solve them out one-by-one. I found a lot of missing places where drawable text could be made as U32Strings.<br \/>\nI succeeded in solving all of them, but there was a small problem with a formatting function, which caused runtime exceptions when I tried to change the languages. Below is the result, with most things working properly! Now it is not broken compared to the previous image, which is nice!<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/0-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-57\" src=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/0-1.png\" alt=\"\" width=\"656\" height=\"438\" srcset=\"https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/0-1.png 656w, https:\/\/blogs.scummvm.org\/ar28\/wp-content\/uploads\/sites\/13\/2022\/04\/0-1-300x200.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><\/p>\n<p>I&#8217;m thinking by next week, I will be polishing up this task! I&#8217;m happy that this task also has a good little progress.<\/p>\n<div style=\"text-align: center;\"><b><i>Thanks for reading!<\/i><\/b><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week, I got started with my new task &#8211; Moving GUI to U32Strings. Before I tell more about it, some miscellaneous things that happened this week: A team-member of ScummVM had previously worked on adding the achievements for some Wintermute games. He was very nice to offer me a game copy to test out [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/posts\/55\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/ar28\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}