mapcomplete/UI/Input/CheckBox.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-07-20 11:30:58 +00:00
import {UIElement} from "../UIElement";
import {UIEventSource} from "../UIEventSource";
2020-07-20 14:57:46 +00:00
import { FilteredLayer } from "../../Logic/FilteredLayer";
2020-07-22 09:49:01 +00:00
import Translations from "../../UI/i18n/Translations";
2020-07-23 23:12:57 +00:00
import instantiate = WebAssembly.instantiate;
2020-07-20 11:30:58 +00:00
export class CheckBox extends UIElement{
2020-07-20 11:37:33 +00:00
private data: UIEventSource<boolean>;
2020-07-20 11:30:58 +00:00
2020-07-22 09:01:25 +00:00
private readonly _data: UIEventSource<boolean>;
private readonly _showEnabled: string|UIElement;
private readonly _showDisabled: string|UIElement;
2020-07-23 23:12:57 +00:00
constructor(showEnabled: string | UIElement, showDisabled: string | UIElement, data: UIEventSource<boolean> | boolean = false) {
2020-07-22 10:17:06 +00:00
super(undefined);
2020-07-23 23:12:57 +00:00
this._data =
data instanceof UIEventSource ? data : new UIEventSource(data ?? false);
2020-07-22 10:17:06 +00:00
this.ListenTo(this._data);
2020-07-22 09:01:25 +00:00
this._showEnabled = showEnabled;
this._showDisabled = showDisabled;
2020-07-22 10:05:29 +00:00
const self = this;
2020-07-22 09:01:25 +00:00
this.onClick(() => {
2020-07-22 10:05:29 +00:00
self._data.setData(!self._data.data);
2020-07-22 09:01:25 +00:00
})
2020-07-23 23:12:57 +00:00
2020-07-20 11:30:58 +00:00
}
2020-07-22 09:05:04 +00:00
InnerRender(): string {
2020-07-22 09:01:25 +00:00
if (this._data.data) {
2020-07-22 09:49:01 +00:00
return Translations.W(this._showEnabled).Render();
2020-07-22 09:01:25 +00:00
} else {
2020-07-22 09:49:01 +00:00
return Translations.W(this._showDisabled).Render();
2020-07-22 09:01:25 +00:00
}
2020-07-20 11:30:58 +00:00
}
}