t_basic.nim 765 B

123456789101112131415161718192021222324252627282930
  1. import sigui, siwin
  2. let win = newOpenglWindow(size=ivec2(1280, 720), title="Hello sigui").newUiWindow
  3. win.makeLayout:
  4. - UiRect():
  5. this.centerIn(parent)
  6. w = 100
  7. h := this.w[] # same as this.bindingValue this.h[]: this.w[]
  8. var state = 0.property
  9. color = binding: # same as this.bindingValue this.color[]:
  10. (
  11. case state[]
  12. of 0: color(1, 0, 0)
  13. of 1: color(0, 1, 0)
  14. else: color(0, 0, 1)
  15. ).lighten(if mouse.hovered[]: 0.3 else: 0)
  16. - this.color.transition(0.4's)
  17. - MouseArea() as mouse:
  18. this.fill(parent)
  19. on this.mouseDownAndUpInside:
  20. state[] = (state[] + 1) mod 3
  21. this.cursor = (ref Cursor)(kind: builtin, builtin: BuiltinCursor.pointingHand)
  22. run win.siwinWindow