できるだけ簡素でメンテナンスしやすい自分用の簡易GUIライブラリ。
- 名前と固定サイズを指定
- 表示/非表示機能
- ドラッグで移動
- 文字列を指定
- デフォルト文字列、id、リサイズの有無を指定
- テキスト、idを指定
二次元のリストでレイアウトを指定。 [ [{テキスト},{テキストエリア}], [{ボタン}] ]
// @require このファイル
(function() {
'use strict';
window.addEventListener('load', () => {
// コンテナを作成 (幅450px、高さ300pxに固定)
const { manager: guiManager } = window.GUIFactory.createContainer(
'Simple GUI',
{ width: '450px', height: '300px' }
);
const components = new Map();
const layout = [
[{ type: 'text', value: '入力してください:' }, { type: 'textarea', id: 'myTextArea', value: 'デフォルト値', resizable: true }],
[{ type: 'button', id: 'myButton', text: 'テキストエリアの内容をログに出力' }],
['これは単なるテキストです。'],
[{ type: 'textarea', id: 'anotherTextArea', value: 'リサイズ不可', resizable: false }],
[{ type: 'button', id: 'copyButton', text: '上のテキストをコピー' }]
];
const contentFragment = window.GUIFactory.createLayout(layout, components);
guiManager.setContent(contentFragment);
const myTextArea = components.get('myTextArea');
const myButton = components.get('myButton');
if (myButton && myTextArea) {
myButton.onclick = () => {
alert(`テキストエリアの内容: ${myTextArea.value}`);
console.log('テキストエリアの内容:', myTextArea.value);
};
}
const anotherTextArea = components.get('anotherTextArea');
const copyButton = components.get('copyButton');
if (copyButton && myTextArea && anotherTextArea) {
copyButton.onclick = () => {
anotherTextArea.value = myTextArea.value;
alert('テキストがコピーされました!');
};
}
});
})();
