One thing's been bugging me about the Nimrod interface file to Claro.
With most GUI toolkits, you have the ability to assign an ID to an object, making it easier to code a single proc for all button actions, for example. You just ask the sender (the button) to give you the ID you set, so you know which button is actually calling the proc at that time.
Claro doesn't seem to have that ability directly, and the Claro.nim file doesn't either.
At least not until now.
What I did was modify the TWidget type in the Claro.nim file, to add an "id" property:
TWidget* {.pure.} = object of TClaroObj
size_req*: ptr TBounds
size*: TBounds
size_ct*: TBounds
supports_alpha*: cint
size_flags*: cint
flags*: cint
visible*: cint
notify_flags*: cint
id*: int # added to provide alternate means of identifiying objects <--HERE
font*: TFont
native*: pointer # native widget
ndata*: pointer # additional native data
container*: pointer # native widget container (if not ->native)
naddress*: array[0..3, pointer] # addressed for something
# we override or need to remember
Up to now, I had been using the "naddress" property to store the button id, but the code to set and get the value was fugly and non-intuitive:
#SETTER
buttons[i].naddress[0] = cast[ptr int](i+1)
#GETTER
var multiplyer = cast[int](button.naddress[0])
Once I added the "id" property, I was able to modify the code to something a lot more clean and intuitive:
#SETTER
buttons[i].id = (i+1)
#GETTER
var multiplyer = button.id
Much cleaner and clear, right?
The other thing that was bothering me was this line:
buf &= IntToStr(multiplyer) & " x " & IntToStr(i) & " = " & IntToStr( multiplyer*i ) & "\n"
Nimrod has a cool shortcut (the Dollar Sign) that converts a number to a string. So now it looks like this:
buf &= $multiplyer & " x " & $i & " = " & $( multiplyer*i ) & "\n"
More in line with a BASIC-Like approach, I think. At least the overall code is cleaner now.
The best thing about being able to add an "id" property with Nimrod is that I didn't have to recompile the Claro library. All I needed to do was modify the Claro.nim file with one simple addition, and change my own code to reflect that.
Very cool language, Nimrod. Thanks John for finding it and sharing!
AIR.