test5.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.on_click =
  11. proc(self: ControlRef, x, y: float) = # This called when the user clicks on the Control node (ColorRect in this case).
  12. colorrect1.move(3, 3)
  13. colorrect.on_press =
  14. proc(self: ControlRef, x, y: float) = # This called when the user holds on the mouse on the Control node.
  15. colorrect.color.r -= 0.001
  16. colorrect.on_release =
  17. proc(self: ControlRef, x, y: float) = # This called when the user no more holds on the mouse.
  18. colorrect.color.r = 1
  19. colorrect.on_focus =
  20. proc(self: ControlRef) = # This called when the Control node gets focus.
  21. echo "hello ^^."
  22. colorrect.on_unfocus =
  23. proc(self: ControlRef) = # This called when the Control node loses focus.
  24. echo "bye :("
  25. colorrect1.on_mouse_enter =
  26. proc(self: ControlRef, x, y: float) = # This called when the mouse enters the Control node.
  27. colorrect1.color = Color(1, 0.6, 1, 0.5)
  28. colorrect1.on_mouse_exit =
  29. proc(self: ControlRef, 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()