Add panel drag resize ctrl

This commit is contained in:
2022-03-01 14:16:14 +08:00
parent 1238bb71bd
commit 38b7f1850e
6 changed files with 246 additions and 47 deletions
+47 -1
View File
@@ -10,12 +10,58 @@ class ILayout {
panles?: string[];
layout?: LayoutDirection;
scale?: number;
id?: number;
}
class Layout extends Emitter<{}> {
interface ILayoutEvent {
layoutChange: Layout;
scaleChange: Layout;
}
class Layout extends Emitter<ILayoutEvent> {
private id: number = 0;
private data: ILayout = {};
private map(fn: (layout: ILayout) => boolean | void, layout?: ILayout) {
const currentLayout = layout ? layout : this.data;
if( fn(currentLayout) ) return;
if (currentLayout.items && currentLayout.items[0]) {
this.map(fn, currentLayout.items[0]);
}
if (currentLayout.items && currentLayout.items[1]) {
this.map(fn, currentLayout.items[1]);
}
}
public getData = (): ILayout => {
return this.data;
}
public setData = (data: ILayout) => {
this.data = data;
this.id = 0;
this.map((layout) => {
layout.id = this.id;
this.id ++;
});
this.emit("layoutChange", this);
}
public setScale = (id: number, scale: number) => {
let change = false;
this.map((layout) => {
if (layout.id === id) {
layout.scale = scale;
change = true;
}
return change;
})
if (change) {
this.emit("scaleChange", this);
}
}
};
export { Layout, ILayout, LayoutDirection };