| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a569bb2 commit d3c39c1
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + import * as model from "./myview"; | ||
| 2 | + import { Button } from "tns-core-modules/ui/button"; | ||
| 3 | + import { Page } from "tns-core-modules/ui/page"; | ||
| 4 | + import { GridLayout, ItemSpec } from "tns-core-modules/ui/layouts/grid-layout"; | ||
| 5 | + | ||
| 6 | + export function onLoaded(args: { eventName: string, object: any }) { | ||
| 7 | + var page = <Page>args.object; | ||
| 8 | + page.bindingContext = new model.ViewModel(); | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + export function onAddRowColumn(args: { eventName: string, object: any }) { | ||
| 12 | + | ||
| 13 | + var layout = <GridLayout>args.object.parent.parent; | ||
| 14 | + var row = new ItemSpec(1, "auto"); | ||
| 15 | + var column = new ItemSpec(1, "auto"); | ||
| 16 | + | ||
| 17 | + layout.addRow(row); | ||
| 18 | + layout.addColumn(column); | ||
| 19 | + | ||
| 20 | + var btn0 = new Button(); | ||
| 21 | + var btn1 = new Button(); | ||
| 22 | + btn0.id = "b0"; | ||
| 23 | + btn1.id = "b1"; | ||
| 24 | + btn0.text = "b0"; | ||
| 25 | + btn1.text = "b1"; | ||
| 26 | + layout.addChild(btn0); | ||
| 27 | + layout.addChild(btn1); | ||
| 28 | + GridLayout.setRow(btn0, 0); | ||
| 29 | + GridLayout.setColumn(btn0, 4); | ||
| 30 | + GridLayout.setRow(btn1, 4); | ||
| 31 | + GridLayout.setColumn(btn1, 0); | ||
| 32 | + GridLayout.setColumnSpan(btn1, 2); | ||
| 33 | + GridLayout.setRowSpan(btn0, 3); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + export function onRemoveRowColumn(args: { eventName: string, object: any }) { | ||
| 37 | + var layout = <GridLayout>args.object.parent.parent; | ||
| 38 | + var itemSpecs, count; | ||
| 39 | + itemSpecs = layout.getRows(); | ||
| 40 | + count = itemSpecs.length; | ||
| 41 | + layout.removeRow(itemSpecs[count - 1]); | ||
| 42 | + itemSpecs = layout.getColumns(); | ||
| 43 | + count = itemSpecs.length; | ||
| 44 | + layout.removeColumn(itemSpecs[count - 1]); | ||
| 45 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + <Page loaded="onLoaded"> | ||
| 2 | + <GridLayout rows="auto, 100, *, 50" columns="auto, 60, *, 40"> | ||
| 3 | + <!-- View Properties --> | ||
| 4 | + <Button text="wh" tap="{{ onWidthHeight }}" id="widthHeight" automationText="widthHeight" style="background-color: lightblue;" /> | ||
| 5 | + <Button text="n" tap="{{ onMinWidthMinHeight }}" column="1" id="minWidthMinHeight" automationText="minWidthMinHeight" style="background-color: lightblue;" /> | ||
| 6 | + <Button text="m" tap="{{ onMargins }}" column="2" id="margins" automationText="margins" style="background-color: lightblue;" /> | ||
| 7 | + <Button text="a" tap="{{ onAlignments }}" row="1" id="alignments" automationText="alignments" style="background-color: lightblue;" /> | ||
| 8 | + <Button text="c" tap="{{ onCollapse }}" row="1" column="1" id="collapse" automationText="collapse" style="background-color: lightblue;" /> | ||
| 9 | + <Button text="v" tap="{{ onVisibile }}" row="1" column="2" id="visible" automationText="visible" style="background-color: lightblue;" /> | ||
| 10 | + <!-- Layout Properties --> | ||
| 11 | + <Button text="p" tap="{{ onPaddings }}" row="2" id="paddings" automationText="paddings" style="background-color: lightgray;" /> | ||
| 12 | + <Button text="all" tap="{{ onAllProperties }}" row="2" column="1" id="allProperties" automationText="allProperties" style="background-color: aquamarine;" /> | ||
| 13 | + <StackLayout row="2" column="2"> | ||
| 14 | + <Button text="1" tap="onAddRowColumn" id="addRowColumn" automationText="addRowColumn" style="background-color: lightgreen;" /> | ||
| 15 | + <Button text="0" tap="onRemoveRowColumn" id="removeRowColumn" automationText="removeRowColumn" style="background-color: lightgreen;" /> | ||
| 16 | + </StackLayout> | ||
| 17 | + </GridLayout> | ||
| 18 | + </Page> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ export function loadExamples() { | |||
| 23 | 23 | examples.set("pwrap", "layouts-percent/wrap-page"); | |
| 24 | 24 | examples.set("passThroughParent", "layouts/passThroughParent-page"); | |
| 25 | 25 | examples.set("stacklayout-6059", "layouts/stacklayout-6059-page"); | |
| 26 | + examples.set("grid-7295", "layouts/grid-7295-page"); | ||
| 26 | 27 | examples.set("safe-area", "layouts/safe-area-page"); | |
| 27 | 28 | ||
| 28 | 29 | return examples; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,6 +119,60 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout> | |||
| 119 | 119 | TKUnit.assertEqual(this.colSpan(test), 1, "'columnSpan' property default value should be 1."); | |
| 120 | 120 | } | |
| 121 | 121 | ||
| 122 | + public test_synonym_property_setting_column_changes_col() { | ||
| 123 | + const test = new Button(); | ||
| 124 | + | ||
| 125 | + test.column = 3; | ||
| 126 | + | ||
| 127 | + TKUnit.assertEqual(test.column, 3, "Setting column should work."); | ||
| 128 | + TKUnit.assertEqual(test.col, 3, "Setting column property should affect col property."); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public test_synonym_property_setting_col_changes_column() { | ||
| 132 | + const test = new Button(); | ||
| 133 | + | ||
| 134 | + test.col = 3; | ||
| 135 | + | ||
| 136 | + TKUnit.assertEqual(test.col, 3, "Setting col should work."); | ||
| 137 | + TKUnit.assertEqual(test.column, 3, "Setting col property should affect column property."); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public test_synonym_property_setColumn_should_set_col_and_column() { | ||
| 141 | + const test = new Button(); | ||
| 142 | + | ||
| 143 | + GridLayout.setColumn(test, 3); | ||
| 144 | + | ||
| 145 | + TKUnit.assertEqual(test.col, 3, "setColumn should set col"); | ||
| 146 | + TKUnit.assertEqual(test.column, 3, "setColumn should set column"); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public test_synonym_property_setting_columnSpan_changes_colSpan() { | ||
| 150 | + const test = new Button(); | ||
| 151 | + | ||
| 152 | + test.columnSpan = 3; | ||
| 153 | + | ||
| 154 | + TKUnit.assertEqual(test.columnSpan, 3, "Setting columnSpan should work."); | ||
| 155 | + TKUnit.assertEqual(test.colSpan, 3, "Setting columnSpan property should affect colSpan property."); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public test_synonym_property_setting_colSpan_changes_columnSpan() { | ||
| 159 | + const test = new Button(); | ||
| 160 | + | ||
| 161 | + test.colSpan = 3; | ||
| 162 | + | ||
| 163 | + TKUnit.assertEqual(test.colSpan, 3, "Setting colSpan should work."); | ||
| 164 | + TKUnit.assertEqual(test.columnSpan, 3, "Setting colSpan property should affect columnSpan property."); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + public test_synonym_property_setColumnSpan_should_set_colSpan_and_columnSpan() { | ||
| 168 | + const test = new Button(); | ||
| 169 | + | ||
| 170 | + GridLayout.setColumnSpan(test, 3); | ||
| 171 | + | ||
| 172 | + TKUnit.assertEqual(test.colSpan, 3, "setColumnSpan should set colSpan"); | ||
| 173 | + TKUnit.assertEqual(test.columnSpan, 3, "setColumnSpan should set columnSpan"); | ||
| 174 | + } | ||
| 175 | + | ||
| 122 | 176 | public test_getRow_shouldThrow_onNullValues() { | |
| 123 | 177 | TKUnit.assertThrows(() => { | |
| 124 | 178 | GridLayout.getRow(null); | |
@@ -250,17 +304,17 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout> | |||
| 250 | 304 | TKUnit.assertEqual( | |
| 251 | 305 | this.row(btn), | |
| 252 | 306 | row, | |
| 253 | - "'row' property not applied For GridLayout addChildAtCell without rowspan." | ||
| 307 | + "'row' property not applied For GridLayout addChildAtCell without rowSpan." | ||
| 254 | 308 | ); | |
| 255 | 309 | TKUnit.assertEqual( | |
| 256 | 310 | this.col(btn), | |
| 257 | 311 | column, | |
| 258 | - "'column' property not applied For GridLayout addChildAtCell without rowspan." | ||
| 312 | + "'column' property not applied For GridLayout addChildAtCell without rowSpan." | ||
| 259 | 313 | ); | |
| 260 | 314 | TKUnit.assertEqual( | |
| 261 | 315 | this.rowSpan(btn), | |
| 262 | 316 | defaultSpanValue, | |
| 263 | - "'rowSpan' property not applied For GridLayout addChildAtCell without rowspan." | ||
| 317 | + "'rowSpan' property not applied For GridLayout addChildAtCell without rowSpan." | ||
| 264 | 318 | ); | |
| 265 | 319 | TKUnit.assertEqual( | |
| 266 | 320 | this.colSpan(btn), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,8 +98,16 @@ export abstract class ViewBase extends Observable { | |||
| 98 | 98 | dock: "left" | "top" | "right" | "bottom"; | |
| 99 | 99 | row: number; | |
| 100 | 100 | col: number; | |
| 101 | + /** | ||
| 102 | + * Setting `column` property is the same as `col` | ||
| 103 | + */ | ||
| 104 | + column: number; | ||
| 101 | 105 | rowSpan: number; | |
| 102 | 106 | colSpan: number; | |
| 107 | + /** | ||
| 108 | + * Setting `columnSpan` property is the same as `colSpan` | ||
| 109 | + */ | ||
| 110 | + columnSpan: number; | ||
| 103 | 111 | domNode: DOMNode; | |
| 104 | 112 | ||
| 105 | 113 | order: Order; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -210,8 +210,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition | |||
| 210 | 210 | dock: "left" | "top" | "right" | "bottom"; | |
| 211 | 211 | row: number; | |
| 212 | 212 | col: number; | |
| 213 | + column: number; // synonym for "col" | ||
| 213 | 214 | rowSpan: number; | |
| 214 | 215 | colSpan: number; | |
| 216 | + columnSpan: number; // synonym for "columnSpan" | ||
| 215 | 217 | ||
| 216 | 218 | order: Order; | |
| 217 | 219 | flexGrow: FlexGrow; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,20 @@ View.prototype.col = 0; | |||
| 16 | 16 | View.prototype.rowSpan = 1; | |
| 17 | 17 | View.prototype.colSpan = 1; | |
| 18 | 18 | ||
| 19 | + Object.defineProperty(View.prototype, "column", { | ||
| 20 | + get(this: View): number { return this.col; }, | ||
| 21 | + set(this: View, value: number) { this.col = value; }, | ||
| 22 | + enumerable: true, | ||
| 23 | + configurable: true | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + Object.defineProperty(View.prototype, "columnSpan", { | ||
| 27 | + get(this: View): number { return this.colSpan; }, | ||
| 28 | + set(this: View, value: number) { this.colSpan = value; }, | ||
| 29 | + enumerable: true, | ||
| 30 | + configurable: true | ||
| 31 | + }); | ||
| 32 | + | ||
| 19 | 33 | function validateItemSpec(itemSpec: ItemSpec): void { | |
| 20 | 34 | if (!itemSpec) { | |
| 21 | 35 | throw new Error("Value cannot be undefined."); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments