////////////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2014-present, Egret Technology. // All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of the Egret nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ////////////////////////////////////////////////////////////////////////////////////// namespace eui { let UIComponentClass = "eui.UIComponent"; /** * The TileLayout class arranges layout elements in columns and rows * of equally-sized cells. * The TileLayout class uses a number of properties that control orientation, * count, size, gap and justification of the columns and the rows * as well as element alignment within the cells. * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @includeExample extension/eui/layout/TileLayoutExample.ts * @language en_US */ /** * TileLayout 类在单元格大小相等的列和行中排列布局元素。 * TileLayout 类使用许多属性来控制列和行的方向、计数、大小、间隙和两端对齐以及单元格内的元素对齐。 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @includeExample extension/eui/layout/TileLayoutExample.ts * @language zh_CN */ export class TileLayout extends LayoutBase { /** * Constructor. * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 构造函数。 * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language zh_CN */ public constructor() { super(); } /** * @private * 标记horizontalGap被显式指定过 */ private explicitHorizontalGap:number = NaN; /** * @private */ private _horizontalGap:number = 6; /** * Horizontal space between columns, in pixels. * * @default 6 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 列之间的水平空间(以像素为单位)。 * * @default 6 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language zh_CN */ public get horizontalGap():number { return this._horizontalGap; } public set horizontalGap(value:number) { value = +value; if (value === this._horizontalGap) return; this.explicitHorizontalGap = value; this._horizontalGap = value; this.invalidateTargetLayout(); } /** * @private * 标记verticalGap被显式指定过 */ private explicitVerticalGap:number = NaN; /** * @private */ private _verticalGap:number = 6; /** * Vertical space between rows, in pixels. * * @default 6 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 行之间的垂直空间(以像素为单位)。 * * @default 6 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language zh_CN */ public get verticalGap():number { return this._verticalGap; } public set verticalGap(value:number) { value = +value; if (value === this._verticalGap) return; this.explicitVerticalGap = value; this._verticalGap = value; this.invalidateTargetLayout(); } /** * @private */ private _columnCount:number = -1; /** * Contain the actual column count. * * @default -1 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 实际列计数。 * * @default -1 * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language zh_CN */ public get columnCount():number { return this._columnCount; } /** * @private */ private _requestedColumnCount:number = 0; /** * Number of columns to be displayed. *
Set to 0 to allow the TileLayout to determine * the column count automatically.
*If the orientation property is set to TileOrientation.ROWS,
* then setting this property has no effect
* In this case, the rowCount is explicitly set, and the
* container width is explicitly set.
设置为 0 会允许 TileLayout 自动确定列计数。
*如果将 orientation 属性设置为 TileOrientation.ROWS,
* 则设置此属性不会产生任何效果。这种情况下,会显式设置 code>rowCount,并显式设置容器宽度。
Set to 0 to remove explicit override and allow the TileLayout to determine * the row count automatically.
*If the orientation property is set to
* TileOrientation.COLUMNS, setting this property has no effect.
* in this case, columnCount is explicitly set, and the
* container height is explicitly set.
设置为 -1 会删除显式覆盖并允许 TileLayout 自动确定行计数。
* 如果将 orientation 属性设置为 TileOrientation.COLUMNS,
* 则设置此属性不会产生任何效果。这种情况下,会显式设置 columnCount,并显式设置容器高度。
*
* @default 0
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get requestedRowCount():number {
return this._requestedRowCount;
}
public set requestedRowCount(value:number) {
value = +value || 0;
if (this._requestedRowCount == value)
return;
this._requestedRowCount = value;
this._rowCount = value;
this.invalidateTargetLayout();
}
/**
* @private
* 外部显式指定的列宽
*/
private explicitColumnWidth:number = NaN;
/**
* @private
*/
private _columnWidth:number = NaN;
/**
* Contain the actual column width, in pixels.
* If not explicitly set, the column width is * determined from the width of the widest element.
* * @default NaN * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 包含实际列宽(以像素为单位)。 *若未显式设置,则从根据最宽的元素的宽度确定列宽度。
* * @default NaN * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language zh_CN */ public get columnWidth():number { return this._columnWidth; } public set columnWidth(value:number) { value = +value; if (value === this._columnWidth) return; this.explicitColumnWidth = value; this._columnWidth = value; this.invalidateTargetLayout(); } /** * @private * 外部显式指定的行高 */ private explicitRowHeight:number = NaN; /** * @private */ private _rowHeight:number = NaN; /** * The row height, in pixels. *If not explicitly set, the row height is * determined from the maximum of elements' height.
* * @default NaN * * @version Egret 2.4 * @version eui 1.0 * @platform Web,Native * @language en_US */ /** * 行高(以像素为单位)。 *如果未显式设置,则从元素的高度的最大值确定行高度。
*
* @default NaN
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get rowHeight():number {
return this._rowHeight;
}
public set rowHeight(value:number) {
value = +value;
if (value === this._rowHeight)
return;
this.explicitRowHeight = value;
this._rowHeight = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _paddingLeft:number = 0;
/**
* @copy eui.LinearLayoutBase#paddingLeft
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
*/
public get paddingLeft():number {
return this._paddingLeft;
}
public set paddingLeft(value:number) {
value = +value || 0;
if (this._paddingLeft == value)
return;
this._paddingLeft = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _paddingRight:number = 0;
/**
* @copy eui.LinearLayoutBase#paddingRight
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
*/
public get paddingRight():number {
return this._paddingRight;
}
public set paddingRight(value:number) {
value = +value || 0;
if (this._paddingRight === value)
return;
this._paddingRight = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _paddingTop:number = 0;
/**
* @copy eui.LinearLayoutBase#paddingTop
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
*/
public get paddingTop():number {
return this._paddingTop;
}
public set paddingTop(value:number) {
value = +value || 0;
if (this._paddingTop == value)
return;
this._paddingTop = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _paddingBottom:number = 0;
/**
* @copy eui.LinearLayoutBase#paddingBottom
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
*/
public get paddingBottom():number {
return this._paddingBottom;
}
public set paddingBottom(value:number) {
value = +value || 0;
if (this._paddingBottom === value)
return;
this._paddingBottom = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _horizontalAlign:string = JustifyAlign.JUSTIFY;
/**
* Specifies how to align the elements within the cells in the horizontal direction.
* Supported values are
* HorizontalAlign.LEFT、HorizontalAlign.CENTER、
* HorizontalAlign.RIGHT、JustifyAlign.JUSTIFY。
*
* @default JustifyAlign.JUSTIFY
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 指定如何在水平方向上对齐单元格内的元素。支持的值有
* HorizontalAlign.LEFT、HorizontalAlign.CENTER、
* HorizontalAlign.RIGHT、JustifyAlign.JUSTIFY。
*
* @default JustifyAlign.JUSTIFY
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get horizontalAlign():string {
return this._horizontalAlign;
}
public set horizontalAlign(value:string) {
if (this._horizontalAlign == value)
return;
this._horizontalAlign = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _verticalAlign:string = JustifyAlign.JUSTIFY;
/**
* 指定如何在垂直方向上对齐单元格内的元素。
* 支持的值有 VerticalAlign.TOP、VerticalAlign.MIDDLE、
* VerticalAlign.BOTTOM、JustifyAlign.JUSTIFY。
* 默认值:JustifyAlign.JUSTIFY。
*
* @default eui.JustifyAlign.JUSTIFY
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* Specifies how to align the elements within the cells in the vertical direction.
* Supported values are
* VerticalAlign.TOP、VerticalAlign.MIDDLE、
* VerticalAlign.BOTTOM、JustifyAlign.JUSTIFY。
*
* @default eui.JustifyAlign.JUSTIFY
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get verticalAlign():string {
return this._verticalAlign;
}
public set verticalAlign(value:string) {
if (this._verticalAlign == value)
return;
this._verticalAlign = value;
this.invalidateTargetLayout();
}
/**
* @private
*/
private _columnAlign:string = ColumnAlign.LEFT;
/**
* Specifies how to justify the fully visible columns to the container width.
*
*
When set to ColumnAlign.LEFT it turns column justification off.
* There may be partially visible columns or whitespace between the last column and
* the right edge of the container. This is the default value.
When set to ColumnAlign.JUSTIFY_USING_GAP the horizontalGap
* actual value increases so that
* the last fully visible column right edge aligns with the container's right edge.
* In case there is only a single fully visible column, the horizontalGap actual value
* increases so that it pushes any partially visible column beyond the right edge
* of the container.
* Note that explicitly setting the horizontalGap property does not turn off
* justification. It only determines the initial gap value.
* Justification may increases it.
When set to ColumnAlign.JUSTIFY_USING_WIDTH the columnWidth
* actual value increases so that
* the last fully visible column right edge aligns with the container's right edge.
* Note that explicitly setting the columnWidth property does not turn off justification.
* It only determines the initial column width value.
* Justification may increases it.
设置为 ColumnAlign.LEFT 时,它会关闭列两端对齐。
* 在容器的最后一列和右边缘之间可能存在部分可见的列或空白。这是默认值。
设置为 ColumnAlign.JUSTIFY_USING_GAP 时,horizontalGap 的实际值将增大,
* 这样最后一个完全可见列右边缘会与容器的右边缘对齐。仅存在一个完全可见列时,
* horizontalGap 的实际值将增大,这样它会将任何部分可见列推到容器的右边缘之外。
* 请注意显式设置 horizontalGap 属性不会关闭两端对齐。它仅确定初始间隙值。两端对齐可能会增大它。
设置为 ColumnAlign.JUSTIFY_USING_WIDTH 时,columnWidth 的实际值将增大,
* 这样最后一个完全可见列右边缘会与容器的右边缘对齐。请注意显式设置 columnWidth 属性不会关闭两端对齐。
* 它仅确定初始列宽度值。两端对齐可能会增大它。
When set to RowAlign.TOP it turns column justification off.
* There might be partially visible rows or whitespace between the last row and
* the bottom edge of the container. This is the default value.
When set to RowAlign.JUSTIFY_USING_GAP the verticalGap
* actual value increases so that
* the last fully visible row bottom edge aligns with the container's bottom edge.
* In case there is only a single fully visible row, the value of verticalGap
* increases so that it pushes any partially visible row beyond the bottom edge
* of the container. Note that explicitly setting the verticalGap does not turn off
* justification, but just determines the initial gap value.
* Justification can then increases it.
When set to RowAlign.JUSTIFY_USING_HEIGHT the rowHeight
* actual value increases so that
* the last fully visible row bottom edge aligns with the container's bottom edge. Note that
* explicitly setting the rowHeight does not turn off justification, but
* determines the initial row height value.
* Justification can then increase it.
设置为 RowAlign.TOP 时,它会关闭列两端对齐。
* 在容器的最后一行和底边缘之间可能存在部分可见的行或空白。这是默认值。
设置为 RowAlign.JUSTIFY_USING_GAP 时,verticalGap 的实际值会增大,
* 这样最后一个完全可见行底边缘会与容器的底边缘对齐。仅存在一个完全可见行时,verticalGap 的值会增大,
* 这样它会将任何部分可见行推到容器的底边缘之外。请注意,显式设置 verticalGap
* 不会关闭两端对齐,而只是确定初始间隙值。两端对齐接着可以增大它。
设置为 RowAlign.JUSTIFY_USING_HEIGHT 时,rowHeight 的实际值会增大,
* 这样最后一个完全可见行底边缘会与容器的底边缘对齐。请注意,显式设置 rowHeight
* 不会关闭两端对齐,而只是确定初始行高度值。两端对齐接着可以增大它。