test25.nim 822 B

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