public void CanFreezeACell() { var cell = new Grid.GridCell(0, 0); cell.Freeze(); Assert.That(cell.IsFrozen, Is.True); }
public void CannotChangeAFrozenCell() { var cell = new Grid.GridCell(0, 0); cell.Freeze(); Assert.Throws(typeof(InvalidOperationException), () => { cell.Value = 9; }); }
/// <summary> /// Gets the grid from TreeView item asynchronous. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public async Task <Grid> GetGridFromTreeViewItemAsync(TreeViewItem <Photo> item) { if (!item.ItemsLoaded) { await AddFilesToTreeViewItemAsync(item); } var grid = new Grid { Caption = _localizer["List of photos in the current directory."] }; var headerRow = new Grid.GridRow(); headerRow.Cells.Add(new Grid.GridHeaderCell { Text = _localizer["Label"], CellIndex = headerRow.Cells.Count, Row = headerRow, Grid = grid }); headerRow.Cells.Add(new Grid.GridHeaderCell { Text = _localizer["Filename"], CellIndex = headerRow.Cells.Count, Row = headerRow, Grid = grid }); headerRow.Cells.Add(new Grid.GridHeaderCell { Text = _localizer["Creation date"], CellIndex = headerRow.Cells.Count, Row = headerRow, Grid = grid }); headerRow.Grid = grid; grid.Header = new Grid.GridHeader { Row = headerRow }; grid.Body = new Grid.GridBody(); foreach (var photo in item.Items) { var row = new Grid.GridRow(); var labelCell = new Grid.GridCell { Text = photo.Label ?? _localizer["Unlabeled"], CellIndex = row.Cells.Count, Row = row, Grid = grid }; row.Cells.Add(labelCell); var nameCell = new Grid.GridCell { Text = Path.GetFileName(photo.Path), CellIndex = row.Cells.Count, Row = row, Grid = grid }; row.Cells.Add(nameCell); var dateTakenCell = new Grid.GridCell { Text = (photo.TakenDate.HasValue ? photo.TakenDate.Value.ToString("F") : _localizer["unknown"]), CellIndex = row.Cells.Count, Row = row, Grid = grid }; row.Cells.Add(dateTakenCell); row.RowIndex = grid.Body.Rows.Count; row.Grid = grid; grid.Body.Rows.Add(row); } if (grid.Body.Rows.Any()) { grid.Body.Rows[0].Cells[0].Selected = true; } return(grid); }
public override void OnInspectorGUI() { Grid comp = (Grid)target; SerializedObject serObj = new SerializedObject(target); SerializedProperty maskProp = serObj.FindProperty("layerMask"); comp.samplingType = (Grid.SamplerType)EditorGUILayout.EnumPopup( "Sampling Type", comp.samplingType); comp.newParameters.gridType = (Grid.GridType) EditorGUILayout.EnumPopup("Grid Type", comp.newParameters.gridType); comp.newParameters.xSize = EditorGUILayout.FloatField("Cell x-size", comp.newParameters.xSize); comp.newParameters.ySize = EditorGUILayout.FloatField("Cell y-size", comp.newParameters.ySize); comp.newParameters.scanHeight = EditorGUILayout.FloatField("Ray Scan Height", comp.newParameters.scanHeight); comp.newParameters.xDimension = EditorGUILayout.IntField("X Dimension", comp.newParameters.xDimension); comp.newParameters.yDimension = EditorGUILayout.IntField("Y Dimension", comp.newParameters.yDimension); comp.noHitNoCell = EditorGUILayout.Toggle("No Hit No cell", comp.noHitNoCell); EditorGUILayout.PropertyField(maskProp); serObj.ApplyModifiedProperties(); // Edge parameters edgeFoldout = EditorGUILayout.Foldout(edgeFoldout, "Edges"); if (edgeFoldout) { EditorGUI.indentLevel = 1; comp.maxEdgeHeightChange = EditorGUILayout.FloatField("Max Height Change", comp.maxEdgeHeightChange); comp.edgeRaycast = EditorGUILayout.Toggle("Edge Raycast", comp.edgeRaycast); comp.edgeCostAlgorithm = (Grid.EdgeCostAlgorithm) EditorGUILayout.EnumPopup("Edge Cost Algorithm", comp.edgeCostAlgorithm); EditorGUI.indentLevel = 0; } if (GUILayout.Button("Generate")) { foreach (Collider obj in FindObjectsOfType(typeof(Collider))) { obj.isTrigger = !obj.isTrigger; obj.isTrigger = !obj.isTrigger; EditorUtility.SetDirty(obj); } EditorUtility.SetDirty(target); comp.FindCells(); } comp.drawEdges = EditorGUILayout.Toggle("Draw Edges", comp.drawEdges); comp.alwaysDrawGrid = EditorGUILayout.Toggle("Always Draw Grid", comp.alwaysDrawGrid); int x, y; Grid.GridCell cell = comp.GetSelectedCell(out x, out y); if (cell != null) { EditorGUILayout.Separator(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Cell", "(" + x + "," + y + ")"); comp.SetCellHeight(x, y, EditorGUILayout.FloatField("Height", comp.GetCellHeight(x, y))); EditorGUI.indentLevel++; int outCount = comp.GetOutEdgeCount(cell); for (int i = 0; i < outCount; i++) { float cost = cell.edges[i]; if (cost == Mathf.Infinity) { continue; } int tx = x + Grid.edgeGridOffsets[i, 0]; int ty = y + Grid.edgeGridOffsets[i, 0]; EditorGUILayout.LabelField("Target", "(" + tx + "," + ty + ")"); cost = EditorGUILayout.FloatField("Cost", cost); if (cost < 0f) { cost = 0f; } cell.edges[i] = cost; EditorGUILayout.Separator(); } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); } if (GUI.changed) { EditorUtility.SetDirty(target); } }