Tab.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. module INSPECTOR{
  2. export abstract class Tab extends BasicElement {
  3. protected _tabbar : TabBar;
  4. // The tab name displayed in the tabbar
  5. public name : string;
  6. protected _isActive: boolean = false;
  7. // The whole panel corresponding to this tab. It's what is displayed when the tab is activacted
  8. protected _panel : HTMLDivElement;
  9. constructor(tabbar:TabBar, name:string) {
  10. super();
  11. this._tabbar = tabbar;
  12. this.name = name;
  13. this._build();
  14. }
  15. /** True if the tab is active, false otherwise */
  16. public isActive() : boolean {
  17. return this._isActive;
  18. }
  19. protected _build() {
  20. this._div.className = 'tab';
  21. this._div.textContent = this.name;
  22. this._div.addEventListener('click', (evt) => {
  23. // Set this tab as active
  24. this._tabbar.switchTab(this);
  25. });
  26. }
  27. /** Set this tab as active or not, depending on the current state */
  28. public active(b:boolean) {
  29. if (b) {
  30. this._div.classList.add('active');
  31. } else {
  32. this._div.classList.remove('active');
  33. }
  34. this._isActive = b;
  35. }
  36. public update() {
  37. // Nothing for the moment
  38. }
  39. /** Creates the tab panel for this tab. */
  40. public getPanel() : HTMLElement {
  41. return this._panel;
  42. }
  43. /** Add this in the propertytab with the searchbar */
  44. public filter(str:string) {};
  45. /** Dispose properly this tab */
  46. public abstract dispose();
  47. /**
  48. * Returns the total width in pixel of this tab, 0 by default
  49. */
  50. public getPixelWidth() : number {
  51. let style = window.getComputedStyle(this._div);
  52. let left = parseFloat(style.marginLeft.substr(0,style.marginLeft.length-2)) ||0;
  53. let right = parseFloat(style.marginRight.substr(0,style.marginRight.length-2)) ||0;
  54. return (this._div.clientWidth || 0) + left + right;
  55. }
  56. }
  57. }