t_anchors.nim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import unittest
  2. import siwin
  3. import sigui
  4. test "anchors":
  5. let window = newOpenglWindow(size = ivec2(1280, 720), title = "anchors").newUiWindow
  6. const typefaceFile = staticRead "Roboto-Regular.ttf"
  7. let typeface = parseTtf(typefaceFile)
  8. window.makeLayout:
  9. this.clearColor = "fff"
  10. const margin = 40
  11. var w = 0'f32.property
  12. var h = 0'f32.property
  13. this.bindingValue w[]: (this.w[] - margin * 4) / 3
  14. this.bindingValue h[]: (this.h[] - margin * 4) / 3
  15. - UiObj() as background
  16. proc text(s: string): UiText =
  17. result = UiText()
  18. initIfNeeded result
  19. result.text[] = s
  20. result.font[] = typeface.withSize(16)
  21. result.makeLayout:
  22. - UiRect():
  23. this.fill parent
  24. drawLayer = after background
  25. color = "c0c0c0"
  26. - UiRectBorder() as rect_tl:
  27. left = parent.left + margin
  28. top = parent.top + margin
  29. - text "right = parent.right":
  30. right = parent.right
  31. - UiRectBorder() as rect_tm:
  32. left = rect_tl.right + margin
  33. top = parent.top + margin
  34. - text "top = parent.bottom":
  35. top = parent.bottom
  36. - UiRectBorder() as rect_tr:
  37. right = parent.right - margin
  38. top = parent.top + margin
  39. - text "bottom = parent.top":
  40. bottom = parent.top
  41. - UiRectBorder() as rect_ml:
  42. left = parent.left + margin
  43. top = rect_tl.bottom + margin
  44. - text "left = parent.left\nright = parent.right\n(fillHorizontal parent)":
  45. # hAlign = CenterAlign
  46. left = parent.left
  47. right = parent.right
  48. - UiRectBorder() as rect_mm:
  49. left = rect_ml.right + margin
  50. top = rect_tl.bottom + margin
  51. - text "centerIn parent":
  52. this.centerIn parent
  53. - UiRectBorder() as rect_mr:
  54. right = parent.right - margin
  55. top = rect_tl.bottom + margin
  56. - text "centerY = parent.center":
  57. centerY = parent.center
  58. - UiRectBorder() as rect_bl:
  59. left = parent.left + margin
  60. bottom = parent.bottom - margin
  61. - text "centerY = parent.top\nright = parent.right":
  62. # this.hAlign[] = CenterAlign
  63. centerY = parent.top
  64. right = parent.right
  65. - UiRectBorder() as rect_bm:
  66. left = rect_bl.right + margin
  67. bottom = parent.bottom - margin
  68. - text "bottom = parent.bottom - 10":
  69. bottom = parent.bottom - 10
  70. - UiRectBorder() as rect_br:
  71. right = parent.right - margin
  72. bottom = parent.bottom - margin
  73. - text "left = parent.left + 10":
  74. left = parent.left + 10
  75. for this in [rect_tl, rect_tm, rect_tr, rect_ml, rect_mm, rect_mr, rect_bl, rect_bm, rect_br]:
  76. w := w[]
  77. h := h[]
  78. borderWidth = 2
  79. color = "333"
  80. run window.siwinWindow