mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #1396 from NativeScript/hhristov/layout-fixes
Fixed bug in GridLayout
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
import page = require("ui/page");
|
||||
import layout = require("ui/layouts/grid-layout");
|
||||
import {Page} from "ui/page";
|
||||
import {GridLayout, ItemSpec, GridUnitType} from "ui/layouts/grid-layout";
|
||||
import {Button} from "ui/button";
|
||||
import TKUnit = require("../TKUnit");
|
||||
import helper = require("./layout-helper");
|
||||
import view = require("ui/core/view");
|
||||
import navHelper = require("../ui/helper");
|
||||
import utils = require("utils/utils");
|
||||
@ -15,69 +14,46 @@ import commonTests = require("./common-layout-tests");
|
||||
|
||||
var DELTA = 1;
|
||||
|
||||
export class MyGridLayout extends layout.GridLayout {
|
||||
public measureCount: number = 0;
|
||||
public layoutCount: number = 0;
|
||||
export class GridLayoutTest extends testModule.UITest<GridLayout> {
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get layouted(): boolean {
|
||||
return this.layoutCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.layoutCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
public create(): layout.GridLayout {
|
||||
return new MyGridLayout();
|
||||
public create(): GridLayout {
|
||||
return new GridLayout();
|
||||
}
|
||||
|
||||
private row(view: view.View): number {
|
||||
return layout.GridLayout.getRow(view);
|
||||
return GridLayout.getRow(view);
|
||||
}
|
||||
|
||||
private rowSpan(view: view.View): number {
|
||||
return layout.GridLayout.getRowSpan(view);
|
||||
return GridLayout.getRowSpan(view);
|
||||
}
|
||||
|
||||
private col(view: view.View): number {
|
||||
return layout.GridLayout.getColumn(view);
|
||||
return GridLayout.getColumn(view);
|
||||
}
|
||||
|
||||
private colSpan(view: view.View): number {
|
||||
return layout.GridLayout.getColumnSpan(view);
|
||||
return GridLayout.getColumnSpan(view);
|
||||
}
|
||||
|
||||
private prepareGridLayout(wait?: boolean) {
|
||||
|
||||
this.testView.addRow(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addRow(new layout.ItemSpec(2, layout.GridUnitType.star));
|
||||
this.testView.addRow(new layout.ItemSpec(layoutHelper.dp(50), layout.GridUnitType.pixel));
|
||||
this.testView.addRow(new layout.ItemSpec(50, layout.GridUnitType.auto));
|
||||
this.testView.addRow(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addRow(new ItemSpec(2, GridUnitType.star));
|
||||
this.testView.addRow(new ItemSpec(layoutHelper.dp(50), GridUnitType.pixel));
|
||||
this.testView.addRow(new ItemSpec(50, GridUnitType.auto));
|
||||
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(2, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(50), layout.GridUnitType.pixel));
|
||||
this.testView.addColumn(new layout.ItemSpec(50, layout.GridUnitType.auto));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(2, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(layoutHelper.dp(50), GridUnitType.pixel));
|
||||
this.testView.addColumn(new ItemSpec(50, GridUnitType.auto));
|
||||
|
||||
for (var r = 0; r < 4; r++) {
|
||||
for (var c = 0; c < 4; c++) {
|
||||
var btn = new helper.MyButton();
|
||||
var btn = new layoutHelper.MyButton();
|
||||
btn.text = "R" + r + "C" + c;
|
||||
layout.GridLayout.setColumn(btn, c);
|
||||
layout.GridLayout.setRow(btn, r);
|
||||
GridLayout.setColumn(btn, c);
|
||||
GridLayout.setRow(btn, r);
|
||||
if (c === 3) {
|
||||
btn.width = layoutHelper.dp(100); // Auto column should take 100px for this test.
|
||||
}
|
||||
@ -124,73 +100,73 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
public test_getRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getRow(null);
|
||||
GridLayout.getRow(null);
|
||||
}, "getRow called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_getRowSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getRowSpan(null);
|
||||
GridLayout.getRowSpan(null);
|
||||
}, "getRowSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_getColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getColumn(null);
|
||||
GridLayout.getColumn(null);
|
||||
}, "getColumn called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_getColumnSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getColumnSpan(null);
|
||||
GridLayout.getColumnSpan(null);
|
||||
}, "getColumnSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_setRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRow(null, 1);
|
||||
GridLayout.setRow(null, 1);
|
||||
}, "setRow called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_setRowSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRowSpan(null, 1);
|
||||
GridLayout.setRowSpan(null, 1);
|
||||
}, "setRowSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_setColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumn(null, 1);
|
||||
GridLayout.setColumn(null, 1);
|
||||
}, "setColumn called with null should throw exception")
|
||||
}
|
||||
|
||||
public test_setColumnSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumnSpan(null, 1);
|
||||
GridLayout.setColumnSpan(null, 1);
|
||||
}, "setColumnSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
public test_setRow_shouldThrow_onNegativeValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRow(new Button(), -1);
|
||||
GridLayout.setRow(new Button(), -1);
|
||||
}, "setRow should throw when value < 0");
|
||||
}
|
||||
|
||||
public test_setRowSpan_shouldThrow_onNotPositiveValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRowSpan(new Button(), 0);
|
||||
GridLayout.setRowSpan(new Button(), 0);
|
||||
}, "setRowSpan should throw when value <= 0");
|
||||
}
|
||||
|
||||
public test_setColumn_shouldThrow_onNegativeValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumn(new Button(), -1);
|
||||
GridLayout.setColumn(new Button(), -1);
|
||||
}, "setColumn should when value < 0");
|
||||
}
|
||||
|
||||
public test_setColumnSpan_shouldThrow_onNotPositiveValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumnSpan(new Button(), 0);
|
||||
GridLayout.setColumnSpan(new Button(), 0);
|
||||
}, "setColumnSpan should throw when value <= 0");
|
||||
}
|
||||
|
||||
@ -253,13 +229,13 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
public test_measuredWidth_when_not_stretched_two_columns() {
|
||||
this.testView.horizontalAlignment = enums.HorizontalAlignment.center;
|
||||
this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(80), layout.GridUnitType.pixel));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(layoutHelper.dp(80), GridUnitType.pixel));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
|
||||
let btn = new Button();
|
||||
btn.text = "A";
|
||||
btn.width = layoutHelper.dp(100);
|
||||
MyGridLayout.setColumnSpan(btn, 2);
|
||||
GridLayout.setColumnSpan(btn, 2);
|
||||
this.testView.addChild(btn);
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
@ -272,22 +248,22 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
public test_measuredWidth_when_not_stretched_three_columns() {
|
||||
this.testView.horizontalAlignment = enums.HorizontalAlignment.center;
|
||||
this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(80), layout.GridUnitType.pixel));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.auto));
|
||||
this.testView.addColumn(new ItemSpec(layoutHelper.dp(80), GridUnitType.pixel));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.auto));
|
||||
|
||||
for (let i = 1; i < 4; i++) {
|
||||
let btn = new Button();
|
||||
btn.text = "A";
|
||||
btn.width = layoutHelper.dp(i * 20);
|
||||
MyGridLayout.setColumn(btn, i - 1);
|
||||
GridLayout.setColumn(btn, i - 1);
|
||||
this.testView.addChild(btn);
|
||||
}
|
||||
|
||||
let btn = new Button();
|
||||
btn.text = "B";
|
||||
btn.width = layoutHelper.dp(100);
|
||||
MyGridLayout.setColumnSpan(btn, 3);
|
||||
GridLayout.setColumnSpan(btn, 3);
|
||||
this.testView.addChild(btn);
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
@ -310,21 +286,21 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
}
|
||||
|
||||
public test_ItemSpec_actualLength_defaultValue() {
|
||||
var def = new layout.ItemSpec(1, layout.GridUnitType.auto);
|
||||
var def = new ItemSpec(1, GridUnitType.auto);
|
||||
TKUnit.assertEqual(def.actualLength, 0, "'actualLength' property default value should be 0.");
|
||||
}
|
||||
|
||||
public test_ItemSpec_constructor_throws_onNegativeValue() {
|
||||
TKUnit.assertThrows(() => {
|
||||
new layout.ItemSpec(-1, layout.GridUnitType.auto);
|
||||
new ItemSpec(-1, GridUnitType.auto);
|
||||
}, "'value' should be positive number.");
|
||||
}
|
||||
|
||||
public test_ItemSpec_constructor_doesnt_throw_onCorrectType() {
|
||||
try {
|
||||
new layout.ItemSpec(1, layout.GridUnitType.auto);
|
||||
new layout.ItemSpec(1, layout.GridUnitType.star);
|
||||
new layout.ItemSpec(1, layout.GridUnitType.pixel);
|
||||
new ItemSpec(1, GridUnitType.auto);
|
||||
new ItemSpec(1, GridUnitType.star);
|
||||
new ItemSpec(1, GridUnitType.pixel);
|
||||
}
|
||||
catch (ex) {
|
||||
TKUnit.assert(false, "ItemSpec type should support auto, star and pixel.");
|
||||
@ -333,13 +309,13 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
public test_ItemSpec_constructor_throws_onWrongType() {
|
||||
TKUnit.assertThrows(() => {
|
||||
new layout.ItemSpec(1, "unsupported");
|
||||
new ItemSpec(1, "unsupported");
|
||||
}, "'ItemSpec type' incorrect value.");
|
||||
}
|
||||
|
||||
public test_ItemSpec_auto() {
|
||||
var w = new layout.ItemSpec(1, layout.GridUnitType.auto);
|
||||
TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.auto, "'gridUnitType' property default value should be 'auto'");
|
||||
var w = new ItemSpec(1, GridUnitType.auto);
|
||||
TKUnit.assertEqual(w.gridUnitType, GridUnitType.auto, "'gridUnitType' property default value should be 'auto'");
|
||||
TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isAuto, true, "'isAuto' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
|
||||
@ -347,8 +323,8 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
}
|
||||
|
||||
public test_ItemSpec_unitType_pixel() {
|
||||
var w = new layout.ItemSpec(6, layout.GridUnitType.pixel);
|
||||
TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.pixel, "'gridUnitType' property default value should be 'pixel'");
|
||||
var w = new ItemSpec(6, GridUnitType.pixel);
|
||||
TKUnit.assertEqual(w.gridUnitType, GridUnitType.pixel, "'gridUnitType' property default value should be 'pixel'");
|
||||
TKUnit.assertEqual(w.isAbsolute, true, "'isAbsolute' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
|
||||
@ -356,8 +332,8 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
}
|
||||
|
||||
public test_ItemSpec_unitType() {
|
||||
var w = new layout.ItemSpec(2, layout.GridUnitType.star);
|
||||
TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.star, "'gridUnitType' property default value should be 'star'");
|
||||
var w = new ItemSpec(2, GridUnitType.star);
|
||||
TKUnit.assertEqual(w.gridUnitType, GridUnitType.star, "'gridUnitType' property default value should be 'star'");
|
||||
TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
|
||||
TKUnit.assertEqual(w.isStar, true, "'isAuto' property default value should be 'true'");
|
||||
@ -384,9 +360,9 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
width = 0;
|
||||
height = 0;
|
||||
for (var c = 0; c < 4; c++) {
|
||||
var btn = <helper.MyButton>this.testView.getChildAt(i++);
|
||||
var btn = <layoutHelper.MyButton>this.testView.getChildAt(i++);
|
||||
if (cols[c].isAbsolute) {
|
||||
width += helper.dip(cols[c].actualLength);
|
||||
width += layoutHelper.dip(cols[c].actualLength);
|
||||
}
|
||||
else {
|
||||
width += btn.getMeasuredWidth();
|
||||
@ -398,7 +374,7 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
maxWidth = Math.max(maxWidth, width);
|
||||
|
||||
if (rows[r].isAbsolute) {
|
||||
maxHeight += helper.dip(rows[r].actualLength);
|
||||
maxHeight += layoutHelper.dip(rows[r].actualLength);
|
||||
}
|
||||
else {
|
||||
maxHeight += height;
|
||||
@ -442,7 +418,7 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
for (var r = 0; r < 4; r++) {
|
||||
|
||||
for (var c = 0; c < 4; c++) {
|
||||
var btn = <helper.MyButton>this.testView.getChildAt(i++);
|
||||
var btn = <layoutHelper.MyButton>this.testView.getChildAt(i++);
|
||||
var col = cols[c];
|
||||
var row = rows[r];
|
||||
|
||||
@ -479,10 +455,10 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
public test_ColumnWidth_when_4stars_and_width_110() {
|
||||
|
||||
this.testView.width = layoutHelper.dp(110);
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
@ -498,7 +474,7 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
this.testView.height = layoutHelper.dp(200);
|
||||
this.testView.width = layoutHelper.dp(200);
|
||||
var btn = new helper.MyButton();
|
||||
var btn = new layoutHelper.MyButton();
|
||||
btn.text = "btn";
|
||||
btn.height = layoutHelper.dp(100);
|
||||
btn.width = layoutHelper.dp(100);
|
||||
@ -513,19 +489,19 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
}
|
||||
|
||||
public test_set_columns_in_XML_comma_separator() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout columns=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
var p = <Page>builder.parse("<Page><GridLayout columns=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <GridLayout>p.content;
|
||||
this.assertColumns(grid);
|
||||
}
|
||||
|
||||
public test_set_columns_in_XML_space_separator() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout columns=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
var p = <Page>builder.parse("<Page><GridLayout columns=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <GridLayout>p.content;
|
||||
this.assertColumns(grid);
|
||||
}
|
||||
|
||||
private assertColumns(grid: layout.GridLayout) {
|
||||
var columns: Array<layout.ItemSpec> = grid.getColumns();
|
||||
private assertColumns(grid: GridLayout) {
|
||||
var columns: Array<ItemSpec> = grid.getColumns();
|
||||
|
||||
TKUnit.assertEqual(columns.length, 4, "columns.length");
|
||||
TKUnit.assert(columns[0].isAuto, "columns[0].isAuto");
|
||||
@ -541,19 +517,20 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
}
|
||||
|
||||
public test_set_rows_in_XML_comma_separator() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout rows=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
this.assertRows(grid);
|
||||
}
|
||||
public test_set_rows_in_XML_space_separator() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout rows=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
var p = <Page>builder.parse("<Page><GridLayout rows=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <GridLayout>p.content;
|
||||
this.assertRows(grid);
|
||||
}
|
||||
|
||||
private assertRows(grid: layout.GridLayout) {
|
||||
var columns: Array<layout.ItemSpec> = grid.getColumns();
|
||||
var rows: Array<layout.ItemSpec> = grid.getRows();
|
||||
public test_set_rows_in_XML_space_separator() {
|
||||
var p = <Page>builder.parse("<Page><GridLayout rows=\"auto * 10* 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <GridLayout>p.content;
|
||||
this.assertRows(grid);
|
||||
}
|
||||
|
||||
private assertRows(grid: GridLayout) {
|
||||
var columns: Array<ItemSpec> = grid.getColumns();
|
||||
var rows: Array<ItemSpec> = grid.getRows();
|
||||
|
||||
TKUnit.assertEqual(rows.length, 4, "rows.length");
|
||||
TKUnit.assert(rows[0].isAuto, "rows[0].isAuto");
|
||||
@ -577,13 +554,13 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
this.testView.width = layoutHelper.dp(300);
|
||||
this.testView.height = layoutHelper.dp(300);
|
||||
|
||||
var btn = new helper.MyButton();
|
||||
var btn = new layoutHelper.MyButton();
|
||||
this.testView.addChild(btn);
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
helper.assertMeasure(btn, 260, 240);
|
||||
helper.assertLayout(btn, 10, 20, 260, 240);
|
||||
layoutHelper.assertMeasure(btn, 260, 240);
|
||||
layoutHelper.assertLayout(btn, 10, 20, 260, 240);
|
||||
}
|
||||
|
||||
public test_codesnippets = function () {
|
||||
@ -592,7 +569,7 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
// ### Creating Grid Layout via code.
|
||||
// ``` JavaScript
|
||||
//var layout = require("ui/layouts/grid-layout");
|
||||
var gridLayout = new layout.GridLayout();
|
||||
var gridLayout = new GridLayout();
|
||||
// ```
|
||||
|
||||
// ### Create grid layout with an xml declaration
|
||||
@ -620,34 +597,34 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
|
||||
// ### Set column property on views - btn1 in first column, btn2 is second and btn3 in third
|
||||
// ``` JavaScript
|
||||
layout.GridLayout.setColumn(btn1, 0);
|
||||
layout.GridLayout.setColumn(btn2, 1);
|
||||
layout.GridLayout.setColumn(btn3, 2);
|
||||
GridLayout.setColumn(btn1, 0);
|
||||
GridLayout.setColumn(btn2, 1);
|
||||
GridLayout.setColumn(btn3, 2);
|
||||
// ```
|
||||
|
||||
// ### Set row property on btn4.
|
||||
// ``` JavaScript
|
||||
layout.GridLayout.setRow(btn4, 1);
|
||||
GridLayout.setRow(btn4, 1);
|
||||
// ```
|
||||
|
||||
// ### Set columnSpan property on btn4 to stretch into all columns
|
||||
// ``` JavaScript
|
||||
layout.GridLayout.setColumnSpan(btn4, 3);
|
||||
GridLayout.setColumnSpan(btn4, 3);
|
||||
// ```
|
||||
|
||||
// ### Create ItemSpec for columns and rows 3 columns - 80px, *, auto size and 2 rows - 100px and auto size
|
||||
// ``` JavaScript
|
||||
//// ItemSpec modes of the column refers to its width.
|
||||
//// Absolute size of the column
|
||||
var firstColumn = new layout.ItemSpec(80, layout.GridUnitType.pixel);
|
||||
var firstColumn = new ItemSpec(80, GridUnitType.pixel);
|
||||
//// Star width means that this column will expand to fill the gap left from other columns
|
||||
var secondColumn = new layout.ItemSpec(1, layout.GridUnitType.star);
|
||||
var secondColumn = new ItemSpec(1, GridUnitType.star);
|
||||
//// Auto size means that column will expand or shrink in order to give enough place for all child UI elements.
|
||||
var thirdColumn = new layout.ItemSpec(1, layout.GridUnitType.auto);
|
||||
var thirdColumn = new ItemSpec(1, GridUnitType.auto);
|
||||
|
||||
//// Star and Auto modes for rows behave like corresponding setting for columns but refer to row height.
|
||||
var firstRow = new layout.ItemSpec(1, layout.GridUnitType.auto);
|
||||
var secondRow = new layout.ItemSpec(1, layout.GridUnitType.star);
|
||||
var firstRow = new ItemSpec(1, GridUnitType.auto);
|
||||
var secondRow = new ItemSpec(1, GridUnitType.star);
|
||||
// ```
|
||||
|
||||
// ### Add columns and rows to GridLayout
|
||||
@ -668,6 +645,34 @@ export class GridLayoutTest extends testModule.UITest<layout.GridLayout> {
|
||||
public test_percent_support_nativeLayoutParams_are_correct() {
|
||||
commonTests.percent_support_nativeLayoutParams_are_correct(this);
|
||||
}
|
||||
|
||||
public test_layout_correctnes() {
|
||||
this.testView.width = layoutHelper.dp(300);
|
||||
this.testView.height = layoutHelper.dp(300);
|
||||
|
||||
let grid = new layoutHelper.MyGridLayout();
|
||||
grid.width = layoutHelper.dp(150);
|
||||
grid.height = layoutHelper.dp(150);
|
||||
grid.horizontalAlignment = enums.HorizontalAlignment.right;
|
||||
grid.verticalAlignment = enums.VerticalAlignment.bottom;
|
||||
|
||||
this.testView.addChild(grid);
|
||||
|
||||
let btn = new layoutHelper.MyButton();
|
||||
btn.width = layoutHelper.dp(75);
|
||||
btn.height = layoutHelper.dp(75);
|
||||
btn.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||
btn.verticalAlignment = enums.VerticalAlignment.bottom;
|
||||
grid.addChild(btn);
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
layoutHelper.assertMeasure(grid, 150, 150);
|
||||
layoutHelper.assertLayout(grid, 150, 150, 150, 150);
|
||||
|
||||
layoutHelper.assertMeasure(btn, 75, 75);
|
||||
layoutHelper.assertLayout(btn, 0, 75, 75, 75);
|
||||
}
|
||||
}
|
||||
|
||||
export function createTestCase(): GridLayoutTest {
|
||||
|
@ -1,16 +1,18 @@
|
||||
import button = require("ui/button");
|
||||
import {View} from "ui/core/view";
|
||||
import {Button} from "ui/button";
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
import {GridLayout} from "ui/layouts/grid-layout";
|
||||
|
||||
import utils = require("utils/utils");
|
||||
import TKUnit = require("../TKUnit");
|
||||
import def = require("./layout-helper");
|
||||
|
||||
var DELTA = 0.1;
|
||||
|
||||
export class NativeButton extends android.widget.Button {
|
||||
|
||||
private owner: MyButton;
|
||||
class NativeButton extends android.widget.Button {
|
||||
private owner: def.MeasuredView;
|
||||
|
||||
constructor(context: android.content.Context, owner: MyButton) {
|
||||
constructor(context: android.content.Context, owner: def.MeasuredView) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
return global.__native(this);
|
||||
@ -18,33 +20,69 @@ export class NativeButton extends android.widget.Button {
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner._oldWidthMeasureSpec = widthMeasureSpec;
|
||||
this.owner._oldHeightMeasureSpec = heightMeasureSpec;
|
||||
|
||||
this.owner._measureWidth = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
this.owner._measureHeight = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||
this.owner.widthMeasureSpec = widthMeasureSpec;
|
||||
this.owner.heightMeasureSpec = heightMeasureSpec;
|
||||
this.owner.measureCount++;
|
||||
}
|
||||
|
||||
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
this.owner._layoutLeft = left;
|
||||
this.owner._layoutTop = top;
|
||||
this.owner._layoutWidth = right - left;
|
||||
this.owner._layoutHeight = bottom - top;
|
||||
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
this.owner.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyButton extends button.Button implements def.MyButton {
|
||||
private _layout: NativeButton;
|
||||
class NativeStackLayout extends org.nativescript.widgets.StackLayout {
|
||||
private owner: def.MeasuredView;
|
||||
|
||||
get android(): NativeButton {
|
||||
constructor(context: android.content.Context, owner: def.MeasuredView) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner.widthMeasureSpec = widthMeasureSpec;
|
||||
this.owner.heightMeasureSpec = heightMeasureSpec;
|
||||
this.owner.measureCount++;
|
||||
}
|
||||
|
||||
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
this.owner.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
class NativeGridLayout extends org.nativescript.widgets.GridLayout {
|
||||
private owner: def.MeasuredView;
|
||||
|
||||
constructor(context: android.content.Context, owner: def.MeasuredView) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner.widthMeasureSpec = widthMeasureSpec;
|
||||
this.owner.heightMeasureSpec = heightMeasureSpec;
|
||||
this.owner.measureCount++;
|
||||
}
|
||||
|
||||
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
this.owner.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyButton extends Button implements def.MyButton {
|
||||
private _layout: android.view.View;
|
||||
|
||||
get android(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): NativeButton {
|
||||
get _nativeView(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
@ -55,16 +93,15 @@ export class MyButton extends button.Button implements def.MyButton {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
_oldWidthMeasureSpec: number = Number.NaN;
|
||||
_oldHeightMeasureSpec: number = Number.NaN;
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
_layoutLeft;
|
||||
_layoutTop;
|
||||
_layoutWidth;
|
||||
_layoutHeight;
|
||||
|
||||
_measureWidth;
|
||||
_measureHeight;
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
@ -74,67 +111,31 @@ export class MyButton extends button.Button implements def.MyButton {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
get measureHeight(): number {
|
||||
return this._measureHeight;
|
||||
}
|
||||
|
||||
get measureWidth(): number {
|
||||
return this._measureWidth;
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this._layoutWidth;
|
||||
return this._layout.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this._layoutHeight;
|
||||
return this._layout.getHeight();
|
||||
}
|
||||
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this._layoutLeft;
|
||||
return this._layout.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this._layoutTop;
|
||||
}
|
||||
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number } {
|
||||
return {
|
||||
widthMeasureSpec: this._oldWidthMeasureSpec,
|
||||
heightMeasureSpec: this._oldHeightMeasureSpec
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class NativeStackLayout extends org.nativescript.widgets.StackLayout {
|
||||
|
||||
private owner: MyStackLayout;
|
||||
|
||||
constructor(context: android.content.Context, owner: MyStackLayout) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner.measureCount++;
|
||||
}
|
||||
|
||||
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
this.owner.arrangeCount++;
|
||||
return this._layout.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
private _layout: NativeStackLayout;
|
||||
private _layout: android.view.View;
|
||||
|
||||
get android(): NativeStackLayout {
|
||||
get android(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): NativeStackLayout {
|
||||
get _nativeView(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
@ -145,6 +146,16 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
@ -152,22 +163,91 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this._layout.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this._layout.getHeight();
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this._layout.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this._layout.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
export function assertMeasure(btn: MyButton, width: number, height: number, name?: string) {
|
||||
name = name ? "[" + name + "]" : "";
|
||||
export class MyGridLayout extends GridLayout implements def.MyGridLayout {
|
||||
private _layout: android.view.View;
|
||||
|
||||
TKUnit.assertAreClose(btn.measureWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(btn.measureHeight, height, DELTA, name + "height");
|
||||
get android(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): android.view.View {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._layout = new NativeGridLayout(this._context, this);
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this._layout.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this._layout.getHeight();
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this._layout.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this._layout.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
export function assertLayout(btn: MyButton, left: number, top: number, width: number, height: number, name?: string): void {
|
||||
export function assertMeasure(view: def.MeasuredView, width: number, height: number, name?: string) {
|
||||
name = name ? "[" + name + "]" : "";
|
||||
|
||||
TKUnit.assertAreClose(btn.layoutLeft, left, DELTA, name + "left");
|
||||
TKUnit.assertAreClose(btn.layoutTop, top, DELTA, name + "top");
|
||||
TKUnit.assertAreClose(btn.layoutWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(btn.layoutHeight, height, DELTA, name + "height");
|
||||
TKUnit.assertAreClose(view.measureWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(view.measureHeight, height, DELTA, name + "height");
|
||||
}
|
||||
|
||||
export function assertLayout(view: def.MeasuredView, left: number, top: number, width: number, height: number, name?: string): void {
|
||||
name = name ? "[" + name + "]" : "";
|
||||
|
||||
TKUnit.assertAreClose(view.layoutLeft, left, DELTA, name + "left");
|
||||
TKUnit.assertAreClose(view.layoutTop, top, DELTA, name + "top");
|
||||
TKUnit.assertAreClose(view.layoutWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(view.layoutHeight, height, DELTA, name + "height");
|
||||
}
|
||||
|
||||
export function dp(value: number): number {
|
||||
|
79
apps/tests/layouts/layout-helper.d.ts
vendored
79
apps/tests/layouts/layout-helper.d.ts
vendored
@ -1,32 +1,85 @@
|
||||
import button = require("ui/button");
|
||||
import {View} from "ui/core/view";
|
||||
import {Button} from "ui/button";
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
import {GridLayout} from "ui/layouts/grid-layout";
|
||||
|
||||
export class MyButton extends button.Button {
|
||||
public measureCount: number;
|
||||
public arrangeCount: number;
|
||||
export interface MeasuredView {
|
||||
measureCount: number;
|
||||
arrangeCount: number;
|
||||
|
||||
measured: boolean;
|
||||
arranged: boolean;
|
||||
|
||||
measureHeight: number;
|
||||
measureWidth: number;
|
||||
|
||||
widthMeasureSpec: number;
|
||||
heightMeasureSpec: number;
|
||||
|
||||
layoutWidth: number;
|
||||
layoutHeight: number;
|
||||
layoutLeft: number;
|
||||
layoutTop: number;
|
||||
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number };
|
||||
}
|
||||
|
||||
export class MyStackLayout extends StackLayout {
|
||||
public measureCount: number;
|
||||
public arrangeCount: number;
|
||||
export class MyButton extends Button implements MeasuredView {
|
||||
measureCount: number;
|
||||
arrangeCount: number;
|
||||
|
||||
public measured: boolean;
|
||||
public arranged: boolean;
|
||||
measured: boolean;
|
||||
arranged: boolean;
|
||||
|
||||
measureHeight: number;
|
||||
measureWidth: number;
|
||||
|
||||
widthMeasureSpec: number;
|
||||
heightMeasureSpec: number;
|
||||
|
||||
layoutWidth: number;
|
||||
layoutHeight: number;
|
||||
layoutLeft: number;
|
||||
layoutTop: number;
|
||||
}
|
||||
|
||||
export function assertMeasure(btn: MyButton, width: number, height: number, name?: string);
|
||||
export function assertLayout(btn: MyButton, left: number, top: number, width: number, height: number, name?: string): void;
|
||||
export class MyStackLayout extends StackLayout implements MeasuredView {
|
||||
measureCount: number;
|
||||
arrangeCount: number;
|
||||
|
||||
measured: boolean;
|
||||
arranged: boolean;
|
||||
|
||||
measureHeight: number;
|
||||
measureWidth: number;
|
||||
|
||||
widthMeasureSpec: number;
|
||||
heightMeasureSpec: number;
|
||||
|
||||
layoutWidth: number;
|
||||
layoutHeight: number;
|
||||
layoutLeft: number;
|
||||
layoutTop: number;
|
||||
}
|
||||
|
||||
export class MyGridLayout extends GridLayout implements MeasuredView {
|
||||
measureCount: number;
|
||||
arrangeCount: number;
|
||||
|
||||
measured: boolean;
|
||||
arranged: boolean;
|
||||
|
||||
measureHeight: number;
|
||||
measureWidth: number;
|
||||
|
||||
widthMeasureSpec: number;
|
||||
heightMeasureSpec: number;
|
||||
|
||||
layoutWidth: number;
|
||||
layoutHeight: number;
|
||||
layoutLeft: number;
|
||||
layoutTop: number;
|
||||
}
|
||||
|
||||
export function assertMeasure(view: MeasuredView, width: number, height: number, name?: string);
|
||||
export function assertLayout(view: MeasuredView, left: number, top: number, width: number, height: number, name?: string): void;
|
||||
export function dip(value: number): number;
|
||||
export function dp(value: number): number;
|
@ -1,14 +1,31 @@
|
||||
import button = require("ui/button");
|
||||
import {Button} from "ui/button";
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
import {GridLayout} from "ui/layouts/grid-layout";
|
||||
import utils = require("utils/utils");
|
||||
import TKUnit = require("../TKUnit");
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
import def = require("./layout-helper");
|
||||
|
||||
var DELTA = 0.1;
|
||||
|
||||
export class MyStackLayout extends StackLayout {
|
||||
export class MyGridLayout extends GridLayout implements def.MyGridLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.widthMeasureSpec = widthMeasureSpec;
|
||||
this.heightMeasureSpec = heightMeasureSpec;
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
@ -17,106 +34,161 @@ export class MyStackLayout extends StackLayout {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyButton extends button.Button {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
private _layoutLeft;
|
||||
private _layoutTop;
|
||||
private _layoutWidth;
|
||||
private _layoutHeight;
|
||||
|
||||
private _measureWidth;
|
||||
private _measureHeight;
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this._measureWidth = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
this._measureHeight = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
this._layoutLeft = left;
|
||||
this._layoutTop = top;
|
||||
this._layoutWidth = right - left;
|
||||
this._layoutHeight = bottom - top;
|
||||
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
|
||||
get measureHeight(): number {
|
||||
return this._measureHeight;
|
||||
}
|
||||
|
||||
get measureWidth(): number {
|
||||
return this._measureWidth;
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this._layoutWidth;
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.right - bounds.left;
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this._layoutHeight;
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.bottom - bounds.top;
|
||||
}
|
||||
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this._layoutLeft;
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.left;
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this._layoutTop;
|
||||
}
|
||||
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number } {
|
||||
return {
|
||||
widthMeasureSpec: (<any>this)._oldWidthMeasureSpec,
|
||||
heightMeasureSpec: (<any>this)._oldHeightMeasureSpec
|
||||
};
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.top;
|
||||
}
|
||||
}
|
||||
|
||||
export function assertMeasure(btn: MyButton, width: number, height: number, name?: string) {
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
var delta = Math.floor(density) !== density ? 1.1 : DELTA;
|
||||
name = name ? "[" + name + "]" : "";
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
TKUnit.assertAreClose(Math.floor(btn.measureWidth / density), width, delta, name + "width");
|
||||
TKUnit.assertAreClose(Math.floor(btn.measureHeight / density), height, delta, name + "height");
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.widthMeasureSpec = widthMeasureSpec;
|
||||
this.heightMeasureSpec = heightMeasureSpec;
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.right - bounds.left;
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.bottom - bounds.top;
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.left;
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.top;
|
||||
}
|
||||
}
|
||||
|
||||
export function assertLayout(btn: MyButton, left: number, top: number, width: number, height: number, name?: string): void {
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
export class MyButton extends Button implements def.MyButton {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
var delta = Math.floor(density) !== density ? 1.1 : DELTA;
|
||||
public widthMeasureSpec: number = Number.NaN;
|
||||
public heightMeasureSpec: number = Number.NaN;
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.widthMeasureSpec = widthMeasureSpec;
|
||||
this.heightMeasureSpec = heightMeasureSpec;
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public get measureWidth() {
|
||||
return utils.layout.getMeasureSpecSize(this.widthMeasureSpec);
|
||||
}
|
||||
|
||||
public get measureHeight() {
|
||||
return utils.layout.getMeasureSpecSize(this.heightMeasureSpec);
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.right - bounds.left;
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.bottom - bounds.top;
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.left;
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
let bounds = this._getCurrentLayoutBounds();
|
||||
return bounds.top;
|
||||
}
|
||||
}
|
||||
|
||||
export function assertMeasure(view: def.MeasuredView, width: number, height: number, name?: string) {
|
||||
name = name ? "[" + name + "]" : "";
|
||||
|
||||
TKUnit.assertAreClose(Math.floor(btn.layoutLeft / density), left, delta, name + "left");
|
||||
TKUnit.assertAreClose(Math.floor(btn.layoutTop / density), top, delta, name + "top");
|
||||
TKUnit.assertAreClose(Math.floor(btn.layoutWidth / density), width, delta, name + "width");
|
||||
TKUnit.assertAreClose(Math.floor(btn.layoutHeight / density), height, delta, name + "height");
|
||||
TKUnit.assertAreClose(view.measureWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(view.measureHeight, height, DELTA, name + "height");
|
||||
}
|
||||
|
||||
export function assertLayout(view: def.MeasuredView, left: number, top: number, width: number, height: number, name?: string): void {
|
||||
name = name ? "[" + name + "]" : "";
|
||||
|
||||
TKUnit.assertAreClose(view.layoutLeft, left, DELTA, name + "left");
|
||||
TKUnit.assertAreClose(view.layoutTop, top, DELTA, name + "top");
|
||||
TKUnit.assertAreClose(view.layoutWidth, width, DELTA, name + "width");
|
||||
TKUnit.assertAreClose(view.layoutHeight, height, DELTA, name + "height");
|
||||
}
|
||||
|
||||
export function dp(value: number): number {
|
||||
|
@ -56,9 +56,7 @@ export class StackLayoutTest extends testModule.UITest<StackLayout> {
|
||||
TKUnit.assertTrue(this.rootLayout.measured, "Layout should be measured.");
|
||||
TKUnit.assertTrue(this.rootLayout.arranged, "Layout should be arranged.");
|
||||
|
||||
var specs = this.btn1._getCurrentMeasureSpecs();
|
||||
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.heightMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Height in vertical orientation.");
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(this.btn1.heightMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Height in vertical orientation.");
|
||||
}
|
||||
|
||||
public test_ShouldMeasureWith_AtMost_OnHorizontal() {
|
||||
@ -70,9 +68,7 @@ export class StackLayoutTest extends testModule.UITest<StackLayout> {
|
||||
TKUnit.assert(this.rootLayout.measured, "Layout should be measured.");
|
||||
TKUnit.assert(this.rootLayout.arranged, "Layout should be arranged.");
|
||||
|
||||
var specs = this.btn1._getCurrentMeasureSpecs();
|
||||
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.widthMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Width in horizontal orientation.");
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(this.btn1.widthMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Width in horizontal orientation.");
|
||||
}
|
||||
|
||||
public test_DesiredSize_Vertical() {
|
||||
|
@ -50,7 +50,8 @@ export function test_loadWithOptionsNoXML() {
|
||||
var v = builder.load({
|
||||
path: "~/xml-declaration/mymodule",
|
||||
name: "MyControl",
|
||||
exports: exports
|
||||
exports: exports,
|
||||
page: new Page()
|
||||
});
|
||||
|
||||
TKUnit.assert(v instanceof view.View, "Expected result: View; Actual result: " + v + ";");
|
||||
@ -102,7 +103,8 @@ export function test_loadWithOptionsWithXML() {
|
||||
var v = builder.load({
|
||||
path: "~/xml-declaration/mymodulewithxml",
|
||||
name: "MyControl",
|
||||
exports: exports
|
||||
exports: exports,
|
||||
page: new Page()
|
||||
});
|
||||
TKUnit.assert(v instanceof view.View, "Expected result: View; Actual result: " + v + ";");
|
||||
};
|
||||
|
@ -107,8 +107,6 @@ export class ItemSpec extends bindable.Bindable implements definition.ItemSpec {
|
||||
export class GridLayout extends layouts.LayoutBase implements definition.GridLayout, view.ApplyXmlAttributes {
|
||||
private _rows: Array<ItemSpec> = new Array<ItemSpec>();
|
||||
private _cols: Array<ItemSpec> = new Array<ItemSpec>();
|
||||
protected _singleRow: ItemSpec = new ItemSpec();
|
||||
protected _singleColumn: ItemSpec = new ItemSpec();
|
||||
|
||||
public static columnProperty = new dependencyObservable.Property("Column", "GridLayout",
|
||||
new proxy.PropertyMetadata(0, dependencyObservable.PropertyMetadataSettings.None, GridLayout.onColumnPropertyChanged, numberUtils.notNegative));
|
||||
@ -154,12 +152,6 @@ export class GridLayout extends layouts.LayoutBase implements definition.GridLay
|
||||
validateArgs(element)._setValue(GridLayout.rowSpanProperty, value);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._singleRow.index = 0
|
||||
this._singleColumn.index = 0;
|
||||
}
|
||||
|
||||
public addRow(itemSpec: ItemSpec) {
|
||||
GridLayout.validateItemSpec(itemSpec);
|
||||
itemSpec.owner = this;
|
||||
@ -260,40 +252,14 @@ export class GridLayout extends layouts.LayoutBase implements definition.GridLay
|
||||
return this._rows.slice();
|
||||
}
|
||||
|
||||
protected getColumn(view: view.View): ItemSpec {
|
||||
if (this._cols.length === 0) {
|
||||
return this._singleColumn;
|
||||
}
|
||||
|
||||
var columnIndex = Math.min(GridLayout.getColumn(view), this._cols.length - 1);
|
||||
return this._cols[columnIndex];
|
||||
protected get columnsInternal(): Array<ItemSpec> {
|
||||
return this._cols;
|
||||
}
|
||||
|
||||
protected getRow(view: view.View): ItemSpec {
|
||||
if (this._rows.length === 0) {
|
||||
return this._singleRow;
|
||||
}
|
||||
|
||||
var columnIndex = Math.min(GridLayout.getRow(view), this._rows.length - 1);
|
||||
return this._rows[columnIndex];
|
||||
protected get rowsInternal(): Array<ItemSpec> {
|
||||
return this._rows;
|
||||
}
|
||||
|
||||
protected getColumnSpan(view: view.View, columnIndex: number): number {
|
||||
if (this._cols.length === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.min(GridLayout.getColumnSpan(view), this._cols.length - columnIndex);
|
||||
}
|
||||
|
||||
protected getRowSpan(view: view.View, rowIndex: number): number {
|
||||
if (this._rows.length === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.min(GridLayout.getRowSpan(view), this._rows.length - rowIndex);
|
||||
}
|
||||
|
||||
|
||||
protected invalidate(): void {
|
||||
//
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user