new() with typedesc

This commit is contained in:
Stefan Salewski 2020-03-09 12:54:04 +01:00
commit e20c95abf5
4 changed files with 44 additions and 24 deletions

View file

@ -1,27 +1,28 @@
# nim c count_button.nim
import gintro/[gtk, glib, gobject, gio]
import gintro/[gtk, gobject, gio]
type
CountButton = ref object of Button
counter: int
when compileOption("gc", "arc"):
when defined(gcDestructors):
proc `=destroy`(x: var typeof(CountButton()[])) =
gtk.`=destroy`(typeof(Button()[])(x))
proc buttonClicked (button: CountButton; decrement: int) =
dec(button.counter, decrement)
button.label = "Counter: " & $button.counter
button.label = "Counter: " & $button.counter
echo "Counter is now: ", button.counter
proc appActivate (app: Application) =
var button: CountButton
#var button: CountButton
let window = newApplicationWindow(app)
window.title = "Count Button"
initButton(button, "Counting down from 100 by 5")
#initButton(button, "Counting down from 100 by 5") # deprecated
let button = newButton(CountButton, "Counting down from 100 by 5")
button.counter = 100
window.add(button)
button.connect("clicked", buttonClicked, 5)
button.connect("clicked", buttonClicked, 5)
window.showAll
proc main =