The example hereunder works, but I was wondering: how does one associate a callback to a button in this context?
https://github.com/Skrylar/nfltk
import fltk as fl
var btn = make_button(64, 64, 100, 64, "Click!")
btn.box = fl.Up_box
btn.labelfont = fl.Helvetica
#btn.labelsize = 12
btn.labeltype = fl.Normal_label
var win = make_window(320, 240, "Test window.")
win.labelfont = fl.Helvetica
win.labelsize = 12
win.begin()
win.add btn
win.endd()
win.show(0, nil)
proc cb(x: int) =
echo ("Hello")
discard fl.run()
Thank you, it should work.
A question. I don't know if there's a way, but would it be possible to define a default callback for all buttons created, so I don't have to define each callback individually? In this case, it would also be necessary to the callback to return some information about the clicked button. That way I could handle all the buttons more efficiently.
Perhaps someone familiar with importing could take a little time to state whether it is indeed possible.
There is the callback: https://github.com/Skrylar/nfltk/blob/master/private/widget.nim#L100
However when you try to do something like this:
proc test() =
echo "Hello"
...
btn.callback = test
The compiler insist looking for "callback" in button.nim, where it doesn't exist.
Error: undeclared field: 'callback=' for type button.Button [type declared in /home/tc/nfltk/private/button.nim(26, 3)]