Skip to content
Snippets Groups Projects
toggle-button.ts 1.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import {
      UIElement,
      InputElement,
      FontElement,
      SurfaceElement,
      FontProperties, SurfaceProperties
    } from '../../models/uI-element';
    import { initFontElement, initSurfaceElement } from '../../util/unit-interface-initializer';
    
    import { ImportModuleVersion } from '../../classes/importModuleVersion';
    
    rhenck's avatar
    rhenck committed
    
    export class ToggleButtonElement extends InputElement implements FontElement, SurfaceElement {
    
    rhenck's avatar
    rhenck committed
      options: string[] = ['A', 'B'];
    
    rhenck's avatar
    rhenck committed
      strikeOtherOptions: boolean = false;
    
      selectionColor: string = 'lightgreen';
    
    rhenck's avatar
    rhenck committed
      verticalOrientation = false;
      dynamicWidth: boolean = true;
    
    rhenck's avatar
    rhenck committed
    
      fontProps: FontProperties;
      surfaceProps: SurfaceProperties;
    
      constructor(serializedElement: Partial<UIElement>) {
        super(serializedElement);
        Object.assign(this, serializedElement);
        this.fontProps = initFontElement(serializedElement);
        this.surfaceProps = initSurfaceElement(serializedElement);
    
    
    rhenck's avatar
    rhenck committed
        this.height = serializedElement.height as number || 25;
    
        this.surfaceProps.backgroundColor =
          serializedElement.surfaceProps?.backgroundColor as string ||
          'transparent';
    
        this.handleBackwardsCompatibility(serializedElement);
      }
    
      handleBackwardsCompatibility(serializedElement: Partial<UIElement>): void {
    
        if ((serializedElement.value || serializedElement.value === 0) &&
          !ImportModuleVersion.isUnitLoaded() && !ImportModuleVersion.verifyVersion()) {
          this.value = Number(this.value) + 1;