t_layers.nim 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. window.makeLayout:
  9. this.clearColor = color(1, 1, 1)
  10. - Styler():
  11. this.fill parent
  12. style = makeStyle:
  13. UiText:
  14. font = typeface.withSize(24)
  15. - UiText() as nonClipped_text:
  16. centerX = nonClipped_rect.center
  17. top = parent.top + 20
  18. text = "non-clipped"
  19. this.fontSize = 32
  20. - UiText() as clipped_text:
  21. centerX = clipped_rect.center
  22. top = parent.top + 20
  23. text = "clipped"
  24. this.fontSize = 32
  25. - UiText():
  26. left = parent.left + 20
  27. bottom = parent.bottom - 10
  28. text = "*not exacly parent, since object is in larger hierarchy: [ ClipRect ] > UiRect > Layout > this"
  29. this.fontSize = 16
  30. - Layout():
  31. left = parent.left + 20
  32. right = parent.right - 20
  33. top = nonClipped_text.bottom + 20
  34. bottom = parent.bottom - 40
  35. fillWithSpaces = true
  36. - UiRect() as nonClipped_rect:
  37. w = 300
  38. this.binding h: parent.h[]
  39. radius = 10
  40. color = color(0.7, 0.7, 0.7)
  41. - Layout():
  42. this.fillVertical(parent, 20)
  43. left = parent.left + 20
  44. orientation = vertical
  45. fillWithSpaces = true
  46. - UiRect() as ncr_a:
  47. h = 80
  48. w = 500
  49. radius = 10
  50. color = color(0.3, 0.3, 1)
  51. - UiText():
  52. centerY = parent.center
  53. left = parent.left + 20
  54. color = color(1, 1, 1)
  55. text = "no modifications"
  56. - UiRect():
  57. drawLayer = after nonClipped_rect
  58. h = 80
  59. w = 500
  60. radius = 10
  61. color = color(0.25, 0.25, 0.85)
  62. - UiText():
  63. centerY = parent.center
  64. left = parent.left + 20
  65. color = color(1, 1, 1)
  66. text = "after parent*"
  67. - UiRect():
  68. drawLayer = before nonClipped_rect
  69. h = 80
  70. w = 500
  71. radius = 10
  72. color = color(0.2, 0.2, 0.7)
  73. - UiText():
  74. centerY = parent.center
  75. right = parent.right - 20
  76. color = color(1, 1, 1)
  77. text = "before parent*"
  78. - ClipRect() as clipped_rect:
  79. w = 300
  80. this.binding h: parent.h[]
  81. radius = 10
  82. - UiRect():
  83. this.fill parent
  84. color = color(0.7, 0.7, 0.7)
  85. - Layout():
  86. top = parent.top + 30
  87. bottom = parent.bottom - 10
  88. left = parent.left - 220
  89. orientation = vertical
  90. fillWithSpaces = true
  91. - UiRect():
  92. h = 80
  93. w = 500
  94. radius = 10
  95. color = color(0.3, 1, 0.3)
  96. - UiText():
  97. centerY = parent.center
  98. right = parent.right - 20
  99. text = "no modifications"
  100. - UiRect():
  101. drawLayer = after clipped_rect
  102. h = 80
  103. w = 500
  104. radius = 10
  105. color = color(0.25, 0.85, 0.25)
  106. - UiText():
  107. centerY = parent.center
  108. left = parent.left + 20
  109. text = "after parent*"
  110. - UiRect():
  111. drawLayer = before clipped_rect
  112. h = 80
  113. w = 500
  114. this.radius[] = 10
  115. this.color[] = color(0.2, 0.7, 0.2)
  116. - UiText():
  117. centerY = parent.center
  118. left = parent.left + 20
  119. text = "before parent*"
  120. run window.siwinWindow