Checkbox.hx 826 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package h2d.comp;
  2. class Checkbox extends Interactive {
  3. public var checked(default, set) : Bool;
  4. public function new(?parent) {
  5. super("checkbox", parent);
  6. checked = false;
  7. }
  8. function set_checked(b) {
  9. toggleClass(":checked", b);
  10. return checked = b;
  11. }
  12. override function resize( ctx : Context ) {
  13. super.resize(ctx);
  14. if( !ctx.measure ) {
  15. input.width = width - (style.marginLeft + style.marginRight);
  16. input.height = height - (style.marginTop + style.marginBottom);
  17. if( checked ) {
  18. var m = style.borderSize + style.tickSpacing;
  19. bg.fillRect(style.tickColor, m, m, input.width - m * 2, input.height - m * 2);
  20. }
  21. }
  22. }
  23. override function onClick() {
  24. checked = !checked;
  25. onChange(checked);
  26. }
  27. public dynamic function onChange( checked : Bool ) {
  28. }
  29. }