added count_button example
This commit is contained in:
parent
b6c508015f
commit
6b38859eab
2 changed files with 84 additions and 3 deletions
30
examples/count_button.nim
Normal file
30
examples/count_button.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# nim c count_button.nim
|
||||
import gintro/[gtk, glib]
|
||||
import gintro/gio except Application, newApplication
|
||||
|
||||
type
|
||||
CountButton = ref object of Button
|
||||
counter: int
|
||||
|
||||
proc buttonClicked (button: CountButton; decrement: int) =
|
||||
dec(button.counter, decrement)
|
||||
button.label = "Counter: " & $button.counter
|
||||
echo "Counter is now: ", button.counter
|
||||
|
||||
proc activate (app: Application) =
|
||||
var button: CountButton
|
||||
let window = newApplicationWindow(app)
|
||||
window.title = "Count Button"
|
||||
initButton(button, "Counting down from 100 by 5")
|
||||
button.counter = 100
|
||||
window.add(button)
|
||||
button.connect("clicked", buttonClicked, 5)
|
||||
window.showAll
|
||||
|
||||
proc main =
|
||||
let app = newApplication("org.gtk.example")
|
||||
connect(app, "activate", activate)
|
||||
discard app.run
|
||||
|
||||
main()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue