test5.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # --- Test 5. Handle Control node events. --- #
  2. import nodesnim
  3. Window("hello world")
  4. var
  5. main = Scene("Main")
  6. colorrect = ColorRect()
  7. colorrect1 = ColorRect()
  8. main.addChild(colorrect)
  9. colorrect.addChild(colorrect1)
  10. colorrect1.click =
  11. proc(x, y: float) = # This called when the user clicks on the Control node (ColorRect in this case).
  12. colorrect1.move(3, 3)
  13. colorrect.press =
  14. proc(x, y: float) = # This called when the user holds on the mouse on the Control node.
  15. colorrect.color.r -= 0.001
  16. colorrect.release =
  17. proc(x, y: float) = # This called when the user no more holds on the mouse.
  18. colorrect.color.r = 1
  19. colorrect.focus =
  20. proc() = # This called when the Control node gets focus.
  21. echo "hello ^^."
  22. colorrect.unfocus =
  23. proc() = # This called when the Control node loses focus.
  24. echo "bye :("
  25. colorrect1.mouse_enter =
  26. proc(x, y: float) = # This called when the mouse enters the Control node.
  27. colorrect1.color = Color(1, 0.6, 1, 0.5)
  28. colorrect1.mouse_exit =
  29. proc(x, y: float) = # This called when the mouse exit from the Control node.
  30. colorrect1.color = Color(1f, 1f, 1f)
  31. addScene(main)
  32. setMainScene("Main")
  33. windowLaunch()