Checkbox.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module INSPECTOR{
  2. /** Any object implementing this interface should
  3. * provide methods to toggle its visibility
  4. */
  5. export interface IToolVisible {
  6. isVisible : () => boolean,
  7. setVisible : (b:boolean) => void;
  8. }
  9. /**
  10. * Checkbox to display/hide the primitive
  11. */
  12. export class Checkbox extends AbstractTreeTool{
  13. private _obj : IToolVisible;
  14. constructor(obj:IToolVisible) {
  15. super ();
  16. this._obj = obj;
  17. this._elem.classList.add('fa-eye');
  18. this._on = this._obj.isVisible();
  19. this._check(true);
  20. }
  21. // For a checkbox, set visible/invisible the corresponding prim
  22. protected action() {
  23. super.action();
  24. // update object and gui according to the new status
  25. this._check();
  26. }
  27. private _check(dontEnable?:boolean) {
  28. if (this._on) {
  29. // set icon eye
  30. this._elem.classList.add('fa-eye');
  31. this._elem.classList.add('active');
  32. this._elem.classList.remove('fa-eye-slash');
  33. }else {
  34. // set icon eye-slash
  35. this._elem.classList.remove('fa-eye');
  36. this._elem.classList.remove('active');
  37. this._elem.classList.add('fa-eye-slash');
  38. }
  39. if (!dontEnable) {
  40. this._obj.setVisible(this._on);
  41. }
  42. }
  43. }
  44. }