Skip to content

local dynamic button

Peter Lewis edited this page Aug 18, 2020 · 4 revisions

local-dynamic-button dynamically creates a (glgui-button-string) or (glgui-button) widget and returns the index for it (which is what (glgui-button-string) and (glgui-button) return). This procedure is useful when some translations of text are in languages where characters are combined, and so the use of the FONTS file cannot properly render these combined characters. Instead, these full strings must be listed in the STRINGS file.

This procedure uses (local-get-text) to get the translation of the string str. If this translation is provided, then a button is created using this string. To use a texture instead, insert "[t]" in the localization csv file.

If (local-get-text) returns "[t]" then a texture will be used in the button instead. The texture symbol is created by appending the language index and ".img" to the str and then converting it to a symbol. See the example below the list of parameters.

Parameter Description
g Graphical User Interface (GUI) for the new widget
bx Lower left corner along the x-axis in pixels
by Lower left corner along the y-axis in pixels
bw Width of the button in pixels
bh Height of the button in pixels
str The string that is a key for the text to get in the current language.
fnt The font used to render the button string (if a button string is used)
callback Function to be called if button is pressed

Example 1

The app below contains the following STRINGS and localization csv files. Note that the localization file will have to be listed in the app's EMBED file. When the app is built, a texture is generated from each string in the STRINGS file, such that there will be restart3.img and exit3.img textures. When run, the csv file below is loaded and the index is set and then a dynamic button is created at position 10, 10. Since the localization file contains a "[t]" for the third language's translation of "exit", the app will look for texture exit3.img, and create a (glgui-button) using this texture.

File STRINGS
Busra-R.ttf 20 'ចាប់ផ្តើមជាថ្មី' restart3 Script=Khmer
Busra-R.ttf 20 'ចាកចេញ' exit3 Script=Khmer

File localization.csv
restart,Restart,Redémarrage,[t]
exit,Exit,Sortie,[t]

(local-load "localization.csv") 
(local-index-set! 3)
(set! gui (make-glgui))
(local-dynamic-button gui 10 10 100 30 "exit" ascii_24.fnt button-callback)
Clone this wiki locally