Parcourir la source

replaced margin and alignment code with margin.computeWithAlignment and removed previous fix for group2d resize issue

Adam Bowman il y a 8 ans
Parent
commit
4b436831dd

+ 8 - 35
canvas2D/src/Engine/babylon.canvas2dLayoutEngine.ts

@@ -329,31 +329,22 @@
                     if (child._isFlagSet(SmartPropertyPrim.flagNoPartOfLayout)) {
                     if (child._isFlagSet(SmartPropertyPrim.flagNoPartOfLayout)) {
                         continue;
                         continue;
                     }
                     }
-                    let layoutArea: Size;
                     if (child._hasMargin) {
                     if (child._hasMargin) {
                         child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, child.actualScale, GridPanelLayoutEngine.dstOffset, GridPanelLayoutEngine.dstArea, true);
                         child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, child.actualScale, GridPanelLayoutEngine.dstOffset, GridPanelLayoutEngine.dstArea, true);
-                        layoutArea = GridPanelLayoutEngine.dstArea.clone();
-                        child.layoutArea = layoutArea;
+                        child.layoutArea = GridPanelLayoutEngine.dstArea.clone();
                     } else {
                     } else {
-                        layoutArea = child.layoutArea;
-                        child.margin.computeArea(child.actualSize, layoutArea);
+                        child.margin.computeArea(child.actualSize, child.layoutArea);
                     }
                     }
-
                 }
                 }
 
 
-
-                let _children = this._children;
-
                 this._updateGrid(prim);
                 this._updateGrid(prim);
 
 
+                let _children = this._children;
                 let rl = this._rows.length;
                 let rl = this._rows.length;
                 let cl = this._columns.length;
                 let cl = this._columns.length;
-
-                let offsetX = 0;
-                let offsetY = 0;
-
                 let columnWidth = 0;
                 let columnWidth = 0;
                 let rowHeight = 0;
                 let rowHeight = 0;
+                let layoutArea = new BABYLON.Size(0, 0);
 
 
                 for(let i = 0; i < _children.length; i++){
                 for(let i = 0; i < _children.length; i++){
                     let children = _children[i];
                     let children = _children[i];
@@ -392,29 +383,11 @@
                                     
                                     
                                 }
                                 }
 
 
-                                if(child.marginAlignment.horizontal === PrimitiveAlignment.AlignRight){
-                                    offsetX = columnWidth - child.layoutArea.width;
-                                }else if(child.marginAlignment.horizontal === PrimitiveAlignment.AlignCenter){
-                                    offsetX = columnWidth*.5 - child.layoutArea.width*.5;
-                                }else{
-                                    offsetX = 0;
-                                }
-
-                                if(child.marginAlignment.vertical === PrimitiveAlignment.AlignTop){
-                                    offsetY = rowHeight - child.layoutArea.height;
-                                }else if(child.marginAlignment.vertical === PrimitiveAlignment.AlignCenter){
-                                    offsetY = rowHeight*.5 - child.layoutArea.height*.5;
-                                }else{
-                                    offsetY = 0;
-                                }
-
-                                var posX = left + offsetX;
-                                var posY = bottom + offsetY;
+                                layoutArea.width = columnWidth;
+                                layoutArea.height = rowHeight;                                
 
 
-                                if(child.layoutAreaPos.x != posX || child.layoutAreaPos.y != posY){
-                                    //must set the layoutAreaPos with Vector2 in order for resizing to work (rather than simply setting the x and y of the layoutAreaPos)
-                                    child.layoutAreaPos = new Vector2(left + offsetX, bottom + offsetY);
-                                }
+                                child.margin.computeWithAlignment(layoutArea, child.actualSize, child.marginAlignment, child.actualScale, GridPanelLayoutEngine.dstOffset, GridPanelLayoutEngine.dstArea);
+                                child.layoutAreaPos = new BABYLON.Vector2(left + GridPanelLayoutEngine.dstOffset.x, bottom + GridPanelLayoutEngine.dstOffset.y);
                                 
                                 
                                 bottom = oBottom;
                                 bottom = oBottom;
                                 rowHeight = oRowHeight;
                                 rowHeight = oRowHeight;

+ 0 - 2
canvas2D/src/Engine/babylon.group2d.ts

@@ -134,8 +134,6 @@
                 rd._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;                
                 rd._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;                
             }
             }
             this.size = size;
             this.size = size;
-            //set actualSize to null so that changing width and height will change contentArea
-            this._actualSize = null;
             this._viewportPosition = Vector2.Zero();
             this._viewportPosition = Vector2.Zero();
             this._viewportSize = Size.Zero();
             this._viewportSize = Size.Zero();
         }
         }