t_layers.nim 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import unittest
  2. import siwin
  3. import sigui
  4. test "layers":
  5. let window = newOpenglWindow(size = ivec2(1280, 720), title = "layers").newUiWindow
  6. const typefaceFile = staticRead "Roboto-Regular.ttf"
  7. let typeface = parseTtf(typefaceFile)
  8. globalDefaultFont = typeface.withSize(24)
  9. window.makeLayout:
  10. this.clearColor = color(1, 1, 1)
  11. - UiText() as nonClipped_text:
  12. centerX = nonClipped_rect.center
  13. top = parent.top + 20
  14. text = "non-clipped"
  15. this.fontSize = 32
  16. - UiText() as clipped_text:
  17. centerX = clipped_rect.center
  18. top = parent.top + 20
  19. text = "clipped"
  20. this.fontSize = 32
  21. - UiText():
  22. left = parent.left + 20
  23. bottom = parent.bottom - 10
  24. text = "*not exacly parent, since object is in larger hierarchy: [ ClipRect ] > UiRect > Layout > this"
  25. this.fontSize = 16
  26. - Layout():
  27. left = parent.left + 20
  28. right = parent.right - 20
  29. top = nonClipped_text.bottom + 20
  30. bottom = parent.bottom - 40
  31. fillWithSpaces = true
  32. - UiRect() as nonClipped_rect:
  33. w = 300
  34. this.binding h: parent.h[]
  35. radius = 10
  36. color = color(0.7, 0.7, 0.7)
  37. - Layout():
  38. this.fillVertical(parent, 20)
  39. left = parent.left + 20
  40. orientation = vertical
  41. fillWithSpaces = true
  42. - UiRect() as ncr_a:
  43. h = 80
  44. w = 500
  45. radius = 10
  46. color = color(0.3, 0.3, 1)
  47. - UiText():
  48. centerY = parent.center
  49. left = parent.left + 20
  50. color = color(1, 1, 1)
  51. text = "no modifications"
  52. - UiRect():
  53. drawLayer = after nonClipped_rect
  54. h = 80
  55. w = 500
  56. radius = 10
  57. color = color(0.3, 0.3, 1)
  58. - UiText():
  59. centerY = parent.center
  60. left = parent.left + 20
  61. color = color(1, 1, 1)
  62. text = "after parent*"
  63. - UiRect():
  64. drawLayer = before nonClipped_rect
  65. h = 80
  66. w = 500
  67. radius = 10
  68. color = color(0.3, 0.3, 1)
  69. - UiText():
  70. centerY = parent.center
  71. right = parent.right - 20
  72. color = color(1, 1, 1)
  73. text = "before parent*"
  74. - ClipRect() as clipped_rect:
  75. w = 300
  76. this.binding h: parent.h[]
  77. radius = 10
  78. - UiRect():
  79. this.fill parent
  80. color = color(0.7, 0.7, 0.7)
  81. - Layout():
  82. top = parent.top + 30
  83. bottom = parent.bottom - 10
  84. left = parent.left - 220
  85. orientation = vertical
  86. fillWithSpaces = true
  87. - UiRect():
  88. h = 80
  89. w = 500
  90. radius = 10
  91. color = color(0.3, 1, 0.3)
  92. - UiText():
  93. centerY = parent.center
  94. right = parent.right - 20
  95. text = "no modifications"
  96. - UiRect():
  97. drawLayer = after clipped_rect
  98. h = 80
  99. w = 500
  100. radius = 10
  101. color = color(0.3, 1, 0.3)
  102. - UiText():
  103. centerY = parent.center
  104. left = parent.left + 20
  105. text = "after parent*"
  106. - UiRect():
  107. drawLayer = before clipped_rect
  108. h = 80
  109. w = 500
  110. this.radius[] = 10
  111. this.color[] = color(0.3, 1, 0.3)
  112. - UiText():
  113. centerY = parent.center
  114. left = parent.left + 20
  115. text = "before parent*"
  116. run window.siwinWindow