Skip to content

local dynamic label

Dustin edited this page Apr 23, 2015 · 6 revisions

local-dynamic-label dynamically creates a (glgui-label-wrapped) or (glgui-pixmap) widget and returns the index for it (which is what (glgui-label-wrapped) and (glgui-pixmap) 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 label is created using it. To use a texture instead, insert "[t]" in the localization csv file.

If (local-get-text) returns "[t]" then a texture will be used instead and a (glgui-pixmap) is created using this texture. 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
lx Lower left corner along the x-axis in pixels
ly Lower left corner along the y-axis in pixels
lw Maximum width of the element in pixels
lh Maximum height of the element 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 label string
color The widget text color
alignl Optional: The horizontal (and optionally vertical) alignment within the width and height.

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 hello3.img and bye3.img textures. When run, the csv file below is loaded and the index is set and then a dynamic label is created at position 10, 100. Since the localization file contains a "[t]" for the third language's translation of "hello", the app will look for texture hello3.img, and create a (glgui-pixmap) using this texture.

File STRINGS
Busra-R.ttf 24 'ជំរាបសួរ' hello3 Script=Khmer
Busra-R.ttf 24 'លា' bye3 Script=Khmer

File localization.csv
hello,Hi,Bonjour,[t]
bye,Goodbye,Au revoir,[t]

(local-load "localization.csv") 
(local-index-set! 3)
(set! gui (make-glgui))
(local-dynamic-label gui 10 100 100 30 "hello" ascii_24.fnt White)

Example 2

Within the same app with the same STRINGS file and localization file, the below example adds a box with "bye" written in all three languages, English at the top, French in the middle, and Khmer at the bottom. This uses the optional alignment parameters. Note that the ascii font will have to be defined in the FONTS file for the app.

(glgui-box gui 10 10 100 90 Orange) 
(local-index-set! 1)
(local-dynamic-label gui 10 12 100 86 "bye" ascii_24.fnt White GUI_ALIGNCENTER GUI_ALIGNTOP)
(local-index-set! 2)
(local-dynamic-label gui 10 12 100 86 "bye" ascii_24.fnt White GUI_ALIGNCENTER GUI_ALIGNCENTER)
(local-index-set! 3)
(local-dynamic-label gui 10 12 100 86 "bye" ascii_24.fnt White GUI_ALIGNCENTER GUI_ALIGNBOTTOM)

The above two examples would produce the below graphics.

Clone this wiki locally