optional data parameter for user input handling

This commit is contained in:
Eon S. Jeon 2018-12-07 16:51:21 +09:00
parent a164d8c102
commit 168e75c656
2 changed files with 21 additions and 3 deletions

View File

@ -168,13 +168,13 @@ class TilingEngine {
* User Input Handling
*/
public handleUserInput = (input: UserInput) => {
public handleUserInput = (input: UserInput, data?: any) => {
const screen = this.getActiveScreen();
if (!screen) return;
debug(() => "handleUserInput: input=" + UserInput[input]);
const overriden = screen.layout.handleUserInput(input);
const overriden = screen.layout.handleUserInput(input, data);
if (overriden) {
this.arrange();
return;
@ -204,6 +204,9 @@ class TilingEngine {
case UserInput.CycleLayout:
this.nextLayout();
break;
case UserInput.SetLayout:
this.setLayout(data);
break;
}
this.arrange();
}
@ -296,6 +299,21 @@ class TilingEngine {
debug(() => screen.layout);
}
public setLayout(cls: any) {
try {
const screen = this.getActiveScreen();
for (let i = 0; i < screen.layouts.length; i++) {
if (screen.layouts[i] instanceof cls) {
screen.layout = screen.layouts[i];
break;
}
}
} catch (e) {
/* Do nothing on error */
debug(() => e);
}
}
/*
* Privates
*/

View File

@ -21,7 +21,7 @@
interface ILayout {
apply(tiles: Tile[], area: Rect): void;
handleUserInput(input: UserInput): boolean;
handleUserInput(input: UserInput, data?: any): boolean;
/* if true, layout completely overrides the default behavior */
isEnabled(): boolean;