test5.nim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # --- Test 5. Work with graphics. --- #
  2. import
  3. nodesnim,
  4. unittest
  5. suite "Work with graphics.":
  6. test "Setup window":
  7. Window("graphics test")
  8. test "Setup scene":
  9. build:
  10. - Scene main
  11. addMainScene(main)
  12. test "Color background":
  13. build:
  14. - Control ctrl
  15. ctrl.resize(256, 96)
  16. ctrl.move(64, 64)
  17. ctrl.setStyle(style(
  18. {
  19. background-color: rgb(33, 65, 87),
  20. border-radius: 8,
  21. border-width: 1,
  22. border-color: rgb(0, 0, 0),
  23. shadow: true,
  24. shadow-offset: 8,
  25. size-anchor: 0.5 0.7
  26. }
  27. ))
  28. getSceneByName("main").addChild(ctrl)
  29. test "Image background":
  30. build:
  31. - Control ctrl1:
  32. call move(350, 100)
  33. call setSizeAnchor(0.2, 0.2)
  34. ctrl1.background.setTexture(load("assets/sharp.jpg"))
  35. ctrl1.background.setCornerRadius(25)
  36. ctrl1.background.setCornerDetail(8)
  37. ctrl1.background.enableShadow(true)
  38. ctrl1.background.setShadowOffset(Vector2(0, 8))
  39. getSceneByName("main").addChild(ctrl1)
  40. test "Gradient background":
  41. build:
  42. - Control ctrl2:
  43. call resize(96, 96)
  44. call setAnchor(0, 0.5, 0, 0.5)
  45. var gradient = GradientDrawable()
  46. gradient.setCornerRadius(16)
  47. gradient.setCornerDetail(16)
  48. gradient.enableShadow(true)
  49. gradient.setShadowOffset(Vector2(15, 15))
  50. gradient.setBorderColor(Color(1.0, 0.5, 0.5, 0.1))
  51. gradient.setBorderWidth(5)
  52. gradient.setStyle(style({
  53. corner-color: "#ff7 #ff7 #f77 #f77"
  54. }))
  55. ctrl2.setBackground(gradient)
  56. getSceneByName("main").addChild(ctrl2)
  57. test "Launch window":
  58. windowLaunch()