|
@@ -237,9 +237,10 @@ export const editActions = EditorModule.action({
|
|
|
}, 100);
|
|
|
},
|
|
|
|
|
|
- async selectObjs(ids: string[]) {
|
|
|
+ async selectObjs(ids: string[], last = "") {
|
|
|
this.store.selected = ids;
|
|
|
this.store.selectId = ids.length > 1 ? Date.now() + "" : "";
|
|
|
+ this.store.lastSelected = last ? last : ( ids.length > 0 ? ids[ids.length-1] : "")
|
|
|
},
|
|
|
|
|
|
// 添加组件到画布
|
|
@@ -315,6 +316,19 @@ export const editActions = EditorModule.action({
|
|
|
ctrlcselected = this.store.selected.slice(0);
|
|
|
},
|
|
|
|
|
|
+ toogleGroup() {
|
|
|
+ if (this.store.selected.length > 1) {
|
|
|
+ this.actions.createGroupComps();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.store.selected.length == 1) {
|
|
|
+ const c = this.helper.findComp(this.store.selected[0]) as DesignComp;
|
|
|
+ if (c.compKey == "Group") {
|
|
|
+ this.actions.cancelGroupComps(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
ctrlv() {
|
|
|
console.log("ctrlv ", this.store.selected);
|
|
|
if (ctrlcselected.length < 1) return;
|
|
@@ -592,6 +606,185 @@ export const editActions = EditorModule.action({
|
|
|
99
|
|
|
);
|
|
|
},
|
|
|
+ //横向对齐
|
|
|
+ setAlignX(flag: 0 | 1 | 2 | 3) {
|
|
|
+ console.log("alignX")
|
|
|
+ const selectCtrl = this.controls.selectCtrl;
|
|
|
+
|
|
|
+ if (this.store.selected.length == 1) {
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
+ const box = objc.getBound();
|
|
|
+ switch(flag) {
|
|
|
+ case 0:
|
|
|
+ selectCtrl.translate(-box.left , 0);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ selectCtrl.translate(-(box.center.x - 187.5) , 0);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ selectCtrl.translate(375 - box.right, 0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
|
+ if (!anchorBox) return;
|
|
|
+
|
|
|
+ const anchor = new CompObject(anchorBox);
|
|
|
+ const anchorRect = anchor.getBox();
|
|
|
+
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
+ let min = 10000, max = -10000;
|
|
|
+ let step = 0;
|
|
|
+ if (flag == 3) {//Y轴均匀排布
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ const r = child.getBox();
|
|
|
+ const x = r.x + r.w / 2.0;
|
|
|
+ if (x <min) min = x;
|
|
|
+ if (x >max ) max = x;
|
|
|
+ })
|
|
|
+ const stepCount = objc.parent.children.length;
|
|
|
+
|
|
|
+ step = (max - min) / (stepCount - 1);
|
|
|
+
|
|
|
+ const stepIndexMap:any = {};
|
|
|
+
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ const r = child.getBox();
|
|
|
+ const x = r.x + r.w / 2.0;
|
|
|
+
|
|
|
+ let minIndex = -1;
|
|
|
+ let minV = 10000;
|
|
|
+ for (let i=0; i<stepCount; i++) {
|
|
|
+ const ty = i*step + min;
|
|
|
+ if ( Math.abs(x - ty) < minV && !stepIndexMap[i]) {
|
|
|
+ minV = Math.abs(x - ty);
|
|
|
+ minIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stepIndexMap[minIndex] = true;
|
|
|
+ child.translate((minIndex*step + min) - x, 0);
|
|
|
+ })
|
|
|
+ objc.updateSize();
|
|
|
+ selectCtrl.upgateGizmoStyle();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ if (child.comp.id == this.store.lastSelected) return;
|
|
|
+ const r = child.getBox();
|
|
|
+ switch(flag) {
|
|
|
+ case 0:
|
|
|
+ child.translate(anchorRect.x -r.x, 0);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ child.translate(anchorRect.x + anchorRect.w / 2.0 - (r.x + r.w/2.0), 0);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ child.translate(anchorRect.x + anchorRect.w - (r.x + r.w), 0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ objc.updateSize();
|
|
|
+ selectCtrl.upgateGizmoStyle();
|
|
|
+ },
|
|
|
+
|
|
|
+ setAlignY(flag: 0 | 1 | 2 | 3) {
|
|
|
+ const selectCtrl = this.controls.selectCtrl;
|
|
|
+ if (this.store.selected.length == 1) {
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
+ const box = objc.getBound();
|
|
|
+
|
|
|
+ const card = new CompObject(this.store.currStreamCard);
|
|
|
+ const cardBox = card.getBox();
|
|
|
+
|
|
|
+ switch(flag) {
|
|
|
+ case 0:
|
|
|
+ selectCtrl.translate(0, -box.top);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ selectCtrl.translate(0 , -(box.center.y - cardBox.h / 2.0));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ selectCtrl.translate(0, cardBox.h - box.bottom);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const anchorBox = this.helper.findComp(this.store.lastSelected);
|
|
|
+ if (!anchorBox) return;
|
|
|
+
|
|
|
+ const anchor = new CompObject(anchorBox);
|
|
|
+ const anchorRect = anchor.getBox();
|
|
|
+
|
|
|
+ const objc = selectCtrl.objContainer as ObjsContainer;
|
|
|
+
|
|
|
+ let min = 10000;
|
|
|
+ let max = -10000;
|
|
|
+ let step = 0;
|
|
|
+
|
|
|
+ if (flag == 3) {//Y轴均匀排布
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ const r = child.getBox();
|
|
|
+ const y = r.y + r.h / 2.0;
|
|
|
+ if (y <min) min = y;
|
|
|
+ if (y >max ) max = y;
|
|
|
+ })
|
|
|
+ const stepCount = objc.parent.children.length;
|
|
|
+
|
|
|
+ step = (max - min) / (stepCount - 1);
|
|
|
+
|
|
|
+ const stepIndexMap:any = {};
|
|
|
+
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ const r = child.getBox();
|
|
|
+ const y = r.y + r.h / 2.0;
|
|
|
+
|
|
|
+ let minIndex = -1;
|
|
|
+ let minV = 10000;
|
|
|
+ for (let i=0; i<stepCount; i++) {
|
|
|
+ const ty = i*step + min;
|
|
|
+ if ( Math.abs(y - ty) < minV && !stepIndexMap[i]) {
|
|
|
+ minV = Math.abs(y - ty);
|
|
|
+ minIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stepIndexMap[minIndex] = true;
|
|
|
+ child.translate(0, (minIndex*step + min) - y);
|
|
|
+ })
|
|
|
+ objc.updateSize();
|
|
|
+ selectCtrl.upgateGizmoStyle();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ objc.parent.children.forEach((c)=>{
|
|
|
+ const child = c as CompObject;
|
|
|
+ if (child.comp.id == this.store.lastSelected) return;
|
|
|
+ const r = child.getBox();
|
|
|
+ switch(flag) {
|
|
|
+ case 0:
|
|
|
+ child.translate(0, anchorRect.y -r.y);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ child.translate(0, anchorRect.y + anchorRect.h / 2.0 - (r.y + r.h /2.0));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ child.translate(0, anchorRect.y + anchorRect.h - (r.y + r.h));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ objc.updateSize();
|
|
|
+ selectCtrl.upgateGizmoStyle();
|
|
|
+ },
|
|
|
// 宽度铺满
|
|
|
fullCompWidth(comp: DesignComp) {
|
|
|
comp.layout.size || (comp.layout.size = []);
|