Open nixfreak opened 2 years ago
Regarding SetAttribute
...
NIUPC module uses PIhandle (pointer to Ihandle, *Ihandle in C).
NIUP module uses Text_t, Button_t, Label_t, etc. types. They can be casted to PIhandle type and used in SetAttribute function you used
Each NIUP object created by Text(), Label(), Button() etc. can set attribute by calling function on object someObj.attributename
Setting attribute
var someText = Text()
someText.value = "lorem ipsum dolorem" # in case there is only one parameter or string
# or
someText.value("lorem ipsum dolorem")
# in case there are multiple parmaters then `attribute=` function can't be used, has to be one with ()
someText.bgcolor(128,0,128) # R G B, type checked for integers
# or
someText.bgcolor("128 0 128") # as string
# or
someText.bgcolor = "128 0 128" # as string
# this is same as
SetAttribute(cast[PIhandle](someText), cstring("BGCOLOR"), cstring("128 0 128"))
# which you have to use if you are calling NIUPC (C like) API
Single string parameter is supported for all attributes. https://github.com/dariolah/niup/blob/master/src/niup/inc/text.nim#L1258
You can check in NIUP cource for specific control what function overloads exists, e.g. bgcolor(int, int, int, int) https://github.com/dariolah/niup/blob/master/src/niup/inc/text.nim#L130
Same for callbacks
proc txt_celcius_cb(ih: PIhandle):cint {.cdecl.} =
echo "this is txt celsius callback"
return IUP_DEFAULT
someText.valuechanged_cb = txt_celcius_cb
# or
someText.valuechanged_cb(txt_celcius_cb)
You can check signature of callback function in NIUP source: https://github.com/dariolah/niup/blob/master/src/niup/inc/text.nim#L1783
Highlighted is callback function signature which matches txt_celcius_cb
Other callback may have other signatures, it is important to use correct ones or app will crash. E.g., K_ANY callback (any key pressed) https://github.com/dariolah/niup/blob/master/src/niup/inc/text.nim#L1638 For this signature callback proc will look like:
proc my_k_any_cb(ih: PIhandle, c: cint):cint {.cdecl.} =
echo "this is k_any callback"
return IUP_DEFAULT
For description of parameters it's best to go to IUP documentation.
PS your callbacks don't do anything, just set up some variables which get optimized away.
Use echo
or something to confirm that you are calling callback. Then do some work in callback, e.g. set value to some control (textLabel_c.value = "whatever"
)
PPS in Nim you can use $
to convert variable to string
var num = 3
echo $num
Trying to re-create tempConvert.c using niup library
I get errors trying to SetAtrribute `ot <Text_t, string, string> but expected one of: proc SetAttribute(ih: PIhandle; name: cstring; value: cstring) first type mismatch at position: 1 required type for ih: PIhandle but expression 'textLabel_c' is of type: Text_t
expression: SetAttribute(textLabel_c, "value", "") In the example do you have to SetStrf to convert to a string? or do I need to parseString? `