mapcomplete/UI/Base/CheckBox.ts
Pieter Vander Vennet 662b752a39 Fix layer toggling
2020-07-22 12:17:06 +02:00

35 lines
No EOL
1.1 KiB
TypeScript

import {UIElement} from "../UIElement";
import {UIEventSource} from "../UIEventSource";
import { FilteredLayer } from "../../Logic/FilteredLayer";
import Translations from "../../UI/i18n/Translations";
export class CheckBox extends UIElement{
private data: UIEventSource<boolean>;
private readonly _data: UIEventSource<boolean>;
private readonly _showEnabled: string|UIElement;
private readonly _showDisabled: string|UIElement;
constructor(showEnabled: string|UIElement, showDisabled: string|UIElement, data: UIEventSource<boolean> = undefined) {
super(undefined);
this._data = data ?? new UIEventSource<boolean>(false);
this.ListenTo(this._data);
this._showEnabled = showEnabled;
this._showDisabled = showDisabled;
const self = this;
this.onClick(() => {
self._data.setData(!self._data.data);
})
}
InnerRender(): string {
if (this._data.data) {
return Translations.W(this._showEnabled).Render();
} else {
return Translations.W(this._showDisabled).Render();
}
}
}