This is an automated email from the ASF dual-hosted git repository. carlosrovira pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push: new 8507615 jewel-tileverticallayout: add vertical version, almost finished 8507615 is described below commit 8507615aa1a86bd2233e511f10467f3d500e3537 Author: Carlos Rovira <carlos.rov...@apache.org> AuthorDate: Thu Jun 4 17:27:07 2020 +0200 jewel-tileverticallayout: add vertical version, almost finished --- .../Jewel/src/main/resources/jewel-manifest.xml | 1 + .../royale/jewel/beads/layouts/StyledLayoutBase.as | 3 +- .../jewel/beads/layouts/TileHorizontalLayout.as | 27 +++++- ...leHorizontalLayout.as => TileVerticalLayout.as} | 107 ++++++++++++--------- 4 files changed, 91 insertions(+), 47 deletions(-) diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml index a39b5cf..74cf130 100644 --- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml +++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml @@ -208,6 +208,7 @@ <component id="VerticalFlowLayout" class="org.apache.royale.jewel.beads.layouts.VerticalFlowLayout"/> <component id="TileLayout" class="org.apache.royale.jewel.beads.layouts.TileLayout"/> <component id="TileHorizontalLayout" class="org.apache.royale.jewel.beads.layouts.TileHorizontalLayout"/> + <component id="TileVerticalLayout" class="org.apache.royale.jewel.beads.layouts.TileVerticalLayout"/> <component id="GridLayout" class="org.apache.royale.jewel.beads.layouts.GridLayout"/> <component id="GridCellLayout" class="org.apache.royale.jewel.beads.layouts.GridCellLayout"/> <component id="TableLayout" class="org.apache.royale.jewel.beads.layouts.TableLayout"/> diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/StyledLayoutBase.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/StyledLayoutBase.as index f30b49a..91bc88b 100644 --- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/StyledLayoutBase.as +++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/StyledLayoutBase.as @@ -27,7 +27,6 @@ package org.apache.royale.jewel.beads.layouts import org.apache.royale.core.ValuesManager; import org.apache.royale.core.layout.ILayoutStyleProperties; import org.apache.royale.events.Event; - import org.apache.royale.events.IEventDispatcher; import org.apache.royale.utils.sendStrandEvent; /** @@ -76,7 +75,7 @@ package org.apache.royale.jewel.beads.layouts { super.strand = value; hostComponent = host as StyledUIBase; - IEventDispatcher(value).addEventListener("beadsAdded", beadsAddedHandler); + listenOnStrand("beadsAdded", beadsAddedHandler); beadsAddedHandler(); } diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as index d7e2f31..9b06f7c 100644 --- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as +++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as @@ -31,8 +31,8 @@ package org.apache.royale.jewel.beads.layouts import org.apache.royale.events.Event; /** - * The TileLayout class bead sizes and positions the elements it manages into rows and columns. - * The size of each element is determined either by setting TileLayout's columnWidth and rowHeight + * The TileHorizontalLayout class bead sizes and positions the elements it manages into rows and columns. + * The size of each element is determined either by setting TileHorizontalLayout's columnWidth and rowHeight * properties, or having the tile size determined by factoring the columnCount into the area assigned * for the layout. * @@ -59,6 +59,29 @@ package org.apache.royale.jewel.beads.layouts public static const LAYOUT_TYPE_NAMES:String = "layout horizontal tile"; /** + * @copy org.apache.royale.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.8 + */ + // override public function set strand(value:IStrand):void + // { + // super.strand = value; + // listenOnStrand("sizeChanged", sizeChangedNeeded); + // } + + /** + * sizeChangedNeeded + * + * @param event + */ + // private function sizeChangedNeeded(event:Event):void + // { + // layout(); + // } + /** * Add class selectors when the component is addedToParent * Otherwise component will not get the class selectors when * perform "removeElement" and then "addElement" diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileVerticalLayout.as similarity index 84% copy from frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as copy to frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileVerticalLayout.as index d7e2f31..74e164b 100644 --- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileHorizontalLayout.as +++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/layouts/TileVerticalLayout.as @@ -28,11 +28,12 @@ package org.apache.royale.jewel.beads.layouts import org.apache.royale.core.ValuesManager; import org.apache.royale.core.layout.EdgeData; import org.apache.royale.core.layout.ILayoutStyleProperties; - import org.apache.royale.events.Event; + import org.apache.royale.events.Event + import org.apache.royale.core.IStrand; /** - * The TileLayout class bead sizes and positions the elements it manages into rows and columns. - * The size of each element is determined either by setting TileLayout's columnWidth and rowHeight + * The TileVerticalLayout class bead sizes and positions the elements it manages into rows and columns. + * The size of each element is determined either by setting TileVerticalLayout's columnWidth and rowHeight * properties, or having the tile size determined by factoring the columnCount into the area assigned * for the layout. * @@ -41,7 +42,7 @@ package org.apache.royale.jewel.beads.layouts * @playerversion AIR 2.6 * @productversion Royale 0.9.8 */ - public class TileHorizontalLayout extends SimpleHorizontalLayout implements ILayoutStyleProperties + public class TileVerticalLayout extends SimpleVerticalLayout implements ILayoutStyleProperties { /** * constructor. @@ -51,14 +52,38 @@ package org.apache.royale.jewel.beads.layouts * @playerversion AIR 2.6 * @productversion Royale 0.9.8 */ - public function TileHorizontalLayout() + public function TileVerticalLayout() { super(); } - public static const LAYOUT_TYPE_NAMES:String = "layout horizontal tile"; + public static const LAYOUT_TYPE_NAMES:String = "layout vertical tile"; /** + * @copy org.apache.royale.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.8 + */ + // override public function set strand(value:IStrand):void + // { + // super.strand = value; + // listenOnStrand("sizeChanged", sizeChangedNeeded); + // } + + /** + * sizeChangedNeeded + * + * @param event + */ + // private function sizeChangedNeeded(event:Event):void + // { + // layout(); + // } + + /** * Add class selectors when the component is addedToParent * Otherwise component will not get the class selectors when * perform "removeElement" and then "addElement" @@ -97,7 +122,7 @@ package org.apache.royale.jewel.beads.layouts return _columnCount; } - private var _requestedColumnCount:int = -1; + private var _requestedRowCount:int = -1; /** * Number of columns to be displayed. * Set to -1 to allow the TileLayout to determine the column count automatically. @@ -107,16 +132,16 @@ package org.apache.royale.jewel.beads.layouts * @playerversion AIR 2.6 * @productversion Royale 0.9.8 */ - [Bindable("requestedColumnCountChanged")] - public function get requestedColumnCount():int + [Bindable("requestedRowCountChanged")] + public function get requestedRowCount():int { - return _requestedColumnCount; + return _requestedRowCount; } - public function set requestedColumnCount(value:int):void + public function set requestedRowCount(value:int):void { if(!isNaN(value)) _columnWidth = NaN; - _requestedColumnCount = value; + _requestedRowCount = value; layout(); } @@ -145,7 +170,7 @@ package org.apache.royale.jewel.beads.layouts public function set columnWidth(value:Number):void { if(!isNaN(value)) - _requestedColumnCount = -1; + _requestedRowCount = -1; _columnWidth = value; layout(); } @@ -364,7 +389,7 @@ package org.apache.royale.jewel.beads.layouts { // trace(" **** TILE LAYOUT ****"); - // trace(" - requestedColumnCount", _requestedColumnCount); + // trace(" - requestedRowCount", _requestedRowCount); // trace(" - columnCount", _columnCount); // trace(" - columnWidth", _columnWidth); // trace(" - horizontalGap", _horizontalGap); @@ -414,33 +439,29 @@ package org.apache.royale.jewel.beads.layouts var adjustedHostHeight:Number = Math.floor(host.height - borderMetrics.top - borderMetrics.bottom); // trace(" - adjustedHeight", adjustedHostHeight); - if (needWidth) - { + if (needHeight) + { // calculate columnCount based of the widesTile - _columnCount = _requestedColumnCount != -1 ? _requestedColumnCount : Math.floor(adjustedHostWidth / (widestTile + _horizontalGap)); - useWidth = _requestedColumnCount == -1 ? widestTile : Math.floor((adjustedHostWidth - _horizontalGap) / _columnCount); + _rowCount = _requestedRowCount != -1 ? _requestedRowCount : Math.floor(adjustedHostHeight / (tallestTile + _verticalGap)); + useHeight = _requestedRowCount == -1 ? tallestTile : Math.floor((adjustedHostHeight - _verticalGap) / _rowCount); } else { // calculate columnCount based on columnWidth - _columnCount = _requestedColumnCount != -1 ? _requestedColumnCount : Math.floor(adjustedHostWidth/ (_columnWidth + _horizontalGap)); - useWidth = _requestedColumnCount == -1 ? _columnWidth : Math.floor((adjustedHostWidth - _horizontalGap) / _columnCount); + _rowCount = _requestedRowCount != -1 ? _requestedRowCount : Math.floor(adjustedHostHeight/ (_rowHeight + _verticalGap)); + useHeight = _requestedRowCount == -1 ? _rowHeight : Math.floor((adjustedHostHeight - _verticalGap) / _rowCount); } // trace(" -- _columnCount", _columnCount); // trace(" -- useWidth", useWidth); // given the width and total number of items, how many rows? // _rowCount = _requestedRowCount != -1 ? _requestedRowCount : Math.floor(adjustedHostHeight / (tallestTile + _verticalGap)); - _rowCount = Math.ceil(realN / _columnCount); + _columnCount = Math.ceil(realN / _rowCount); // trace(" -- _rowCount", _rowCount); - if (needHeight) - { - useHeight = tallestTile; - // if (host.isHeightSizedToContent()) useHeight = 30; // default height - // else useHeight = Math.floor((adjustedHostHeight + _verticalGap) / numRows); - // trace(" -- useHeight", useHeight); + if (needWidth) + { + useWidth = widestTile; } else { - // _rowCount = _requestedRowCount != -1 ? _requestedRowCount : Math.floor(adjustedHostHeight / (_rowHeight + _verticalGap)); - useHeight = _rowHeight; + useWidth = _columnWidth; } // trace(" -- useHeight", useHeight); @@ -452,30 +473,30 @@ package org.apache.royale.jewel.beads.layouts // trace(i, i % _columnCount, i % _rowCount); - // add horizontalGap - if(i % _columnCount != 0) - child.positioner.style.marginLeft = _horizontalGap + "px"; - else - child.positioner.style.marginLeft = null; - // add verticalGap - if(i >= _columnCount) + if(i % _rowCount != 0) child.positioner.style.marginTop = _verticalGap + "px"; else child.positioner.style.marginTop = null; + + // add horizontalGap + if(i >= _rowCount) + child.positioner.style.marginLeft = _horizontalGap + "px"; + else + child.positioner.style.marginLeft = null; //if the parent width/height not explicitly set, we can't calculate the child width/height if(useWidth > 0) - child.width = _requestedColumnCount == -1 ? useWidth : useWidth - _horizontalGap; + child.width = useWidth;// - _verticalGap; if(useHeight > 0) - child.height = useHeight;// - _verticalGap; - // child.height = _requestedColumnCount == -1 ? useHeight : useHeight - _verticalGap; + child.height = _requestedRowCount == -1 ? useHeight : useHeight - _verticalGap; + // child.height = _requestedRowCount == -1 ? useHeight : useHeight - _verticalGap; // add dummy margin: avoid a tile from the next row stay in the previous row due to flexbox algorithm - if(i % _columnCount == _columnCount - 1) - child.positioner.style.marginRight = Math.floor(adjustedHostWidth - (1 + child.width + (child.width + _horizontalGap) * (_columnCount - 1))) + "px"; - else - child.positioner.style.marginRight = null; + // if(i % _columnCount == _columnCount - 1) + // child.positioner.style.marginRight = Math.floor(adjustedHostWidth - (1 + child.width + (child.width + _horizontalGap) * (_columnCount - 1))) + "px"; + // else + // child.positioner.style.marginRight = null; child.dispatchEvent('sizeChanged'); }