test27.nim 886 B

123456789101112131415161718192021222324252627282930313233343536
  1. # --- Test 27. Use TextureButton node. --- #
  2. import nodesnim
  3. Window("hello world")
  4. var
  5. mainobj: SceneObj
  6. main = Scene("Main", mainobj)
  7. buttonobj: TextureButtonObj
  8. button = TextureButton(buttonobj)
  9. norm_texture = load("assets/button_normal.png", GL_RGBA)
  10. hover_texture = load("assets/button_hover.png", GL_RGBA)
  11. press_texture = load("assets/button_press.png", GL_RGBA)
  12. main.addChild(button)
  13. env.setBackgroundColor(Color(0xf2f2f7ff'u32))
  14. button.text = "Press me!"
  15. button.resize(256, 64)
  16. button.setAnchor(0.5, 0.5, 0.5, 0.5)
  17. button.setNormalTexture(norm_texture)
  18. button.setHoverTexture(hover_texture)
  19. button.setPressTexture(press_texture)
  20. button.on_touch =
  21. proc(self: TextureButtonPtr, x, y: float) = # This called when user clicks on the button
  22. button.text = "Clicked in " & $x & ", " & $y & " position."
  23. addScene(main)
  24. setMainScene("Main")
  25. windowLaunch()