simonkrauter/NiGui

Assigning events dynamically

demetera opened this issue · 3 comments

Hello,

thanks for amazing GUI library!

In this code I have elements (in this case Buttons) added to container and seq[Button] dynamically (it should be Label and Checkbox in one horizontal layout in the future, but I'm only experimenting for now):

import nigui

var buts: seq[Button]

app.init()

var cont = newLayoutContainer(Layout_Vertical)

var label = newLabel("")
cont.add(label)

for i in 1..3:
  var but = newButton("Button " & $i)
  but.onClick = proc(event: ClickEvent) = label.text = but.text
  buts.add(but)
  
for button in buts:
  cont.add(button)

var window = newWindow()
window.width = 800
window.height = 600
window.add(cont)
window.show()

app.run()

But when I run the code, the event triggers only last Button, which is Button 3.
Should seq to contain Button elements along with onClick events as one object, or do I have to use another method here?

Thank you!

I'm pretty sure it's the same as #167, see my comment there.

Thanks a lot. I got it. Apologies for raising duplicated issue

No problem. I appreciate when a questioner writes a good description!