t_styles.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import unittest
  2. import siwin
  3. import sigui
  4. test "styles":
  5. let window = newOpenglWindow(size = ivec2(1280, 720), title = "styles").newUiWindow
  6. const typefaceFile = staticRead "Roboto-Regular.ttf"
  7. let typeface = parseTtf(typefaceFile)
  8. let darkTheme = makeStyle:
  9. UiText:
  10. font = typeface.withSize(24)
  11. color = "ffffff"
  12. UiRect:
  13. color = "303030"
  14. radius = 5
  15. - UiText():
  16. this.centerIn parent
  17. text = "rect"
  18. color = "808080"
  19. let lightTheme = makeStyle:
  20. apply darkTheme
  21. UiText:
  22. color = "000000"
  23. UiRect:
  24. color = "e0e0e0"
  25. radius = 5
  26. - UiText():
  27. this.centerIn parent
  28. text = "this should not be visible"
  29. color = "808080"
  30. window.makeLayout:
  31. this.clearColor = "202020"
  32. - Styler():
  33. this.fill parent
  34. style = lightTheme
  35. style = darkTheme
  36. - UiRect():
  37. x = 20
  38. y = 20
  39. w = 200
  40. h = 100
  41. - UiRect():
  42. this.centerIn root
  43. w = 50
  44. h = 50
  45. - UiText():
  46. bottom = parent.bottom
  47. text = "text with changed font"
  48. font = typeface.withSize(16)
  49. - UiRect():
  50. right = parent.right
  51. bottom = parent.bottom
  52. w = 100
  53. h = 50
  54. run window.siwinWindow