mirror of
https://github.com/esjeon/krohnkite.git
synced 2024-10-04 07:18:09 +03:00
optional data parameter for user input handling
This commit is contained in:
parent
a164d8c102
commit
168e75c656
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user