blob: 26d94d8adc34968e5478243fd8db2ce5146aa48d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
const FocusElement = require('./form/FocusElement')
const Pane = require('./Pane')
const telc = require('../util/telchars')
module.exports = class Dialog extends FocusElement {
// A simple base dialog.
//
// Emits the 'cancelled' event when the cancel key (escape) is pressed,
// which should (probably) be handled by the dialog's creator.
//
// Doesn't do anything when focused by default - this should be overridden
// in subclasses.
//
// Automatically adjusts to fill its parent. Has a pane child (this.pane),
// but the pane isn't adjusted at all (you should change its size and
// likely center it in your subclass).
constructor() {
super()
this.pane = new Pane()
this.addChild(this.pane)
}
fixLayout() {
this.w = this.parent.contentW
this.h = this.parent.contentH
}
keyPressed(keyBuf) {
if (telc.isCancel(keyBuf)) {
this.emit('cancelled')
}
}
}
|