5620 GridLayout addChild to set row and column (#6411)

This commit is contained in:
Rakesh Girase
2018-10-19 13:20:41 +01:00
committed by Alexander Vakrilov
parent 4407af7dd6
commit a3f149325f
3 changed files with 132 additions and 0 deletions

View File

@ -183,6 +183,121 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
GridLayout.setColumnSpan(new Button(), 0);
}
public test_addChildAtCell_with_all_params() {
let btn = new Button();
let row: number = 1;
let column: number = 2;
let rowSpan: number = 3;
let columnSpan: number = 4;
this.testView.addChildAtCell(btn, row, column, rowSpan, columnSpan);
TKUnit.assertEqual(
this.row(btn),
row,
"'row' property not applied For GridLayout addChildAtCell."
);
TKUnit.assertEqual(
this.col(btn),
column,
"'column' property not applied For GridLayout addChildAtCell."
);
TKUnit.assertEqual(
this.rowSpan(btn),
rowSpan,
"'rowSpan' property not applied For GridLayout addChildAtCell."
);
TKUnit.assertEqual(
this.colSpan(btn),
columnSpan,
"'columnSpan' property not applied For GridLayout addChildAtCell."
);
}
public test_addChildAtCell_without_optional_params() {
let btn = new Button();
let row: number = 1;
let column: number = 2;
let defaultSpanValue: number = 1;
this.testView.addChildAtCell(btn, row, column);
TKUnit.assertEqual(
this.row(btn),
row,
"'row' property not applied For GridLayout addChildAtCell."
);
TKUnit.assertEqual(
this.col(btn),
column,
"'column' property not applied For GridLayout addChildAtCell."
);
TKUnit.assertEqual(
this.rowSpan(btn),
defaultSpanValue,
"'rowSpan' property not applied For GridLayout addChildAtCell without optional params."
);
TKUnit.assertEqual(
this.colSpan(btn),
defaultSpanValue,
"'colSpan' property not applied For GridLayout addChildAtCell without optional params."
);
}
public test_addChildAtCell_without_rowSpan() {
let btn = new Button();
let row: number = 1;
let column: number = 2;
let columnSpan: number = 2;
let defaultSpanValue: number = 1;
this.testView.addChildAtCell(btn, row, column, undefined, columnSpan);
TKUnit.assertEqual(
this.row(btn),
row,
"'row' property not applied For GridLayout addChildAtCell without rowspan."
);
TKUnit.assertEqual(
this.col(btn),
column,
"'column' property not applied For GridLayout addChildAtCell without rowspan."
);
TKUnit.assertEqual(
this.rowSpan(btn),
defaultSpanValue,
"'rowSpan' property not applied For GridLayout addChildAtCell without rowspan."
);
TKUnit.assertEqual(
this.colSpan(btn),
columnSpan,
"'columnSpan' property not applied For GridLayout addChildAtCell without rowspan."
);
}
public test_addChildAtCell_without_columnSpan() {
let btn = new Button();
let row: number = 1;
let column: number = 2;
let rowSpan: number = 2;
let defaultSpanValue: number = 1;
this.testView.addChildAtCell(btn, row, column, rowSpan);
TKUnit.assertEqual(
this.row(btn),
row,
"'row' property not applied For GridLayout addChildAtCell without columnSpan."
);
TKUnit.assertEqual(
this.col(btn),
column,
"'column' property not applied For GridLayout addChildAtCell without columnSpan."
);
TKUnit.assertEqual(
this.rowSpan(btn),
rowSpan,
"'rowSpan' property not applied For GridLayout addChildAtCell without columnSpan."
);
TKUnit.assertEqual(
this.colSpan(btn),
defaultSpanValue,
"'columnSpan' property not applied For GridLayout addChildAtCell without columnSpan."
);
}
public test_addRow_shouldThrow_onNullValues() {
TKUnit.assertThrows(() => {
this.testView.addRow(null);

View File

@ -178,6 +178,18 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition {
this.invalidate();
}
public addChildAtCell(view: View, row: number, column: number, rowSpan?: number, columnSpan?: number): void {
this.addChild(view);
GridLayoutBase.setRow(view, row);
GridLayoutBase.setColumn(view, column);
if (rowSpan) {
GridLayoutBase.setRowSpan(view, rowSpan);
}
if (columnSpan) {
GridLayoutBase.setColumnSpan(view, columnSpan);
}
}
public removeRow(itemSpec: ItemSpec): void {
if (!itemSpec) {
throw new Error("Value is null.");

View File

@ -101,6 +101,11 @@ export class GridLayout extends LayoutBase {
*/
public addRow(itemSpec: ItemSpec): void;
/**
* Adds a child at specific cell in GridLayout. Optional rowSpan and columnSpan attributes
*/
public addChildAtCell(view: View, row: number, column: number, rowSpan?: number, columnSpan?: number): void;
/**
* Removes a column specification from a GridLayout.
*/