You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/07/18 08:04:45 UTC
[24/50] git commit: [flex-sdk] [refs/heads/master] - FLEX_34368 Add
percentageWidth to GridColumn. Accept patch from Alexander Konovalov with
some modifications. Needs tests. Current tests pass
FLEX_34368 Add percentageWidth to GridColumn. Accept patch from Alexander Konovalov with some modifications. Needs tests. Current tests pass
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/8e546012
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/8e546012
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/8e546012
Branch: refs/heads/master
Commit: 8e546012128025dcdf148fbecd5c704d85878b43
Parents: 0c91593
Author: Alex Harui <ah...@apache.org>
Authored: Sun Jun 22 07:28:31 2014 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Sun Jun 22 07:28:31 2014 -0700
----------------------------------------------------------------------
.../spark/components/gridClasses/GridColumn.as | 43 ++++++++
.../components/gridClasses/GridViewLayout.as | 106 ++++++++++++++++++-
2 files changed, 145 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/8e546012/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as
index ff7b298..5c3236f 100644
--- a/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as
+++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as
@@ -1180,6 +1180,49 @@ public class GridColumn extends EventDispatcher
dispatchChangeEvent("maxWidthChanged");
}
+ [Inspectable(category="General")]
+ [PercentProxy("percentWidth")]
+
+ /**
+ * @private
+ */
+ private var _percentWidth:Number = NaN;
+
+ [Bindable("widthChanged")]
+ [Inspectable(environment="none")]
+
+ /**
+ * The width of this column as a percentage of DataGrid width.
+ * Setting this property does not change the <code>width</code>
+ * or <code>minWidth</code> properties.
+ *
+ * @default NaN
+ *
+ * @langversion 3.0
+ * @playerversion Flash 13
+ * @playerversion AIR 13.0
+ * @productversion Flex 4.12.2
+ */
+ public function get percentWidth ():Number
+ {
+ return _percentWidth;
+ }
+
+ /**
+ * @private
+ */
+ public function set percentWidth(value:Number):void
+ {
+ if (_percentWidth == value)
+ {
+ return;
+ }
+ this._percentWidth = value;
+ invalidateGrid();
+
+ dispatchChangeEvent("widthChanged");
+ }
+
//----------------------------------
// rendererIsEditable
//----------------------------------
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/8e546012/frameworks/projects/spark/src/spark/components/gridClasses/GridViewLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridViewLayout.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridViewLayout.as
index 76febe3..4dbaf11 100644
--- a/frameworks/projects/spark/src/spark/components/gridClasses/GridViewLayout.as
+++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridViewLayout.as
@@ -1289,18 +1289,67 @@ public class GridViewLayout extends LayoutBase
const startCellX:Number = gridDimensionsView.getCellX(0 /* rowIndex */, firstVisibleColumnIndex);
const columnGap:int = gridDimensionsView.columnGap;
- for (var columnIndex:int = firstVisibleColumnIndex;
+ var columnIndex : int;
+ var column : GridColumn;
+ var totalWidthCoef : Number = 0;
+ var contentFreeSpace : Number = grid.contentWidth;
+ var gridFreeSpace : Number = grid.width;
+ for (columnIndex = 0; (columnIndex < columnCount); columnIndex++)
+ {
+ column = getGridColumn(columnIndex);
+ if (isNaN(column.width) && column.visible)
+ {
+ totalWidthCoef += column.percentWidth;
+ }
+ else
+ {
+ if (!isNaN(column.width) && column.visible)
+ {
+ contentFreeSpace -= column.width;
+ gridFreeSpace -= column.width;
+ }
+ }
+ }
+ var freeSpace : Number = gridFreeSpace < 0 ? contentFreeSpace : gridFreeSpace;
+ var unusedFreeSpace : Number = freeSpace;
+
+ for (columnIndex = firstVisibleColumnIndex;
(width > 0) && (columnIndex >= 0) && (columnIndex < columnCount);
columnIndex = getNextVisibleColumnIndex(columnIndex))
{
var cellHeight:Number = gridDimensionsView.getTypicalCellHeight(columnIndex);
var cellWidth:Number = gridDimensionsView.getTypicalCellWidth(columnIndex);
- var column:GridColumn = getGridColumn(columnIndex);
+ column = getGridColumn(columnIndex);
if (!isNaN(column.width))
{
cellWidth = column.width;
gridDimensionsView.setTypicalCellWidth(columnIndex, cellWidth);
+ }
+ else
+ {
+ if (totalWidthCoef > 0)
+ {
+ cellWidth = Math.round(column.percentWidth / totalWidthCoef * (freeSpace > 0 ? freeSpace : 0));
+ if (cellWidth < column.minWidth)
+ {
+ cellWidth = column.minWidth;
+ unusedFreeSpace -= cellWidth;
+ }
+ else
+ {
+ if (cellWidth > unusedFreeSpace)
+ {
+ cellWidth = unusedFreeSpace;
+ unusedFreeSpace = 0;
+ }
+ else
+ {
+ unusedFreeSpace -= cellWidth;
+ }
+ }
+ gridDimensionsView.setTypicalCellWidth(columnIndex, cellWidth);
+ }
}
if (isNaN(cellWidth) || isNaN(cellHeight))
@@ -1344,12 +1393,36 @@ public class GridViewLayout extends LayoutBase
const requestedColumnCount:int = grid.requestedColumnCount; // TBD GridView...
var measuredColumnCount:int = 0;
- for (var columnIndex:int = 0; (columnIndex < columnCount); columnIndex++)
+ var columnIndex : int;
+ var column : GridColumn;
+ var totalWidthCoef : Number = 0;
+ var contentFreeSpace : Number = grid.contentWidth;
+ var gridFreeSpace : Number = grid.width;
+ for (columnIndex = 0; (columnIndex < columnCount); columnIndex++)
+ {
+ column = getGridColumn(columnIndex);
+ if (isNaN(column.width) && column.visible)
+ {
+ totalWidthCoef += column.percentWidth;
+ }
+ else
+ {
+ if (!isNaN(column.width) && column.visible)
+ {
+ contentFreeSpace -= column.width;
+ gridFreeSpace -= column.width;
+ }
+ }
+ }
+ var freeSpace : Number = gridFreeSpace < 0 ? contentFreeSpace : gridFreeSpace;
+ var unusedFreeSpace : Number = freeSpace;
+
+ for (columnIndex = 0; (columnIndex < columnCount); columnIndex++)
{
var cellHeight:Number = gridDimensionsView.getTypicalCellHeight(columnIndex);
var cellWidth:Number = gridDimensionsView.getTypicalCellWidth(columnIndex);
- var column:GridColumn = getGridColumn(columnIndex);
+ column = getGridColumn(columnIndex);
// GridColumn.visible==false columns have a typical size of (0,0)
// to distinguish them from the GridColumn.visible==true columns
@@ -1366,6 +1439,31 @@ public class GridViewLayout extends LayoutBase
{
cellWidth = column.width;
gridDimensionsView.setTypicalCellWidth(columnIndex, cellWidth);
+ }
+ else
+ {
+ if (totalWidthCoef > 0)
+ {
+ cellWidth = Math.round(column.percentWidth / totalWidthCoef * (freeSpace > 0 ? freeSpace : 0));
+ if (cellWidth < column.minWidth)
+ {
+ cellWidth = column.minWidth;
+ unusedFreeSpace -= cellWidth;
+ }
+ else
+ {
+ if (cellWidth > unusedFreeSpace)
+ {
+ cellWidth = unusedFreeSpace;
+ unusedFreeSpace = 0;
+ }
+ else
+ {
+ unusedFreeSpace -= cellWidth;
+ }
+ }
+ gridDimensionsView.setTypicalCellWidth(columnIndex, cellWidth);
+ }
}
var needTypicalRenderer:Boolean = (requestedColumnCount == -1) || (measuredColumnCount < requestedColumnCount);