public void CreateGrid() { grid = new Grid(row, col); cellWidth = gridWidth / col; cellHeight = gridHeight / row; cellViewArray = new View[row, col]; tileViewArray = new View[row, col]; for (int y = 0; y < row; y++) { for (int x = 0; x < col; x++) { grid.CellArray[x, y] = new Cell(x, y); GameObject cellObject = Instantiate <GameObject>(cellViewTemplate.gameObject, cellViewTemplate.transform.parent); cellObject.SetActive(true); View cellView = cellObject.GetComponent <View>(); cellView.SetSize(x, y, cellWidth, cellHeight); cellView.SetColorFade(); cellViewArray[x, y] = cellView; } } Vector3[] corners = GetCornors(); gridOffsetX = corners[0].x; gridOffsetY = corners[0].y; }
public void AddNewComponents(View[,] comps, bool replaceOld = true, bool vertical = false) { if (replaceOld) { MGrid.Children.Clear(); } Components = comps; for (var i = 0; i < comps.GetLength(0); i++) { for (var j = 0; j < comps.GetLength(1); j++) { var e = Components[i, j]; if (e == null) { continue; } if (vertical) { MGrid.Children.Add(e, j, i); } else { MGrid.Children.Add(e, i, j); } } } }
private static double[,] GetNumbersFromEntries(View[,] es) { var sx = es.GetLength(0); var sy = es.GetLength(1); var n = new double[sx, sy]; for (var i = 0; i < sx; i++) { for (var j = 0; j < sy; j++) { var e = es[i, j] as Entry; var vs = e?.Text; if (vs == null) { continue; } double v; if (double.TryParse(vs, out v)) { n[i, j] = v; } } } return(n); }
public GridView() { //1 column 1 row _columns.Add(ColumnDefinition.Star(1)); _rows.Add(RowDefinition.Star(1)); ChildLocations = new View[1, 1]; }
// provides new views to use public void SetChildren(View[,] newChildren) { // Remove removed children, then add new children // This is done in two passes in case a child moved to another location int rowNumber, columnNumber; for (columnNumber = 0; columnNumber < newChildren.GetLength(0); columnNumber++) { for (rowNumber = 0; rowNumber < newChildren.GetLength(1); rowNumber++) { View newChild = newChildren[columnNumber, rowNumber]; View oldChild; if (this.children == null) { oldChild = null; } else { oldChild = this.children[columnNumber, rowNumber]; } if (newChild != oldChild) { if (oldChild != null) { this.Children.Remove(oldChild); } } } } // add new children for (columnNumber = 0; columnNumber < newChildren.GetLength(0); columnNumber++) { for (rowNumber = 0; rowNumber < newChildren.GetLength(1); rowNumber++) { View newChild = newChildren[columnNumber, rowNumber]; View oldChild; if (this.children == null) { oldChild = null; } else { oldChild = this.children[columnNumber, rowNumber]; } if (newChild != oldChild) { if (newChild != null) { this.Children.Add(newChild); Grid.SetColumn(newChild, columnNumber); Grid.SetRow(newChild, rowNumber); } } } } this.InvalidateMeasure(); this.children = newChildren; }
public void SetRows(params RowDefinition[] rows) { if (Children.Count > 0) { throw new InvalidOperationException("Cannot change rows once children are added"); } if ((rows is null) || (rows.Length == 0)) { throw new ArgumentException("Must specify at least one row", nameof(rows)); } _rows.Clear(); _rows.AddRange(rows); ChildLocations = new View[_columns.Count, _rows.Count]; }
public void SetColumns(params ColumnDefinition[] columns) { if (Children.Any()) { throw new InvalidOperationException("Cannot change columns once children are added"); } if (columns?.Any() != true) { throw new ArgumentException("Must specify at least one column", nameof(columns)); } _columns.Clear(); _columns.AddRange(columns); ChildLocations = new View[_columns.Count, _rows.Count]; }
public void SetGridComponents(View[,] cmps, bool reset = false) { if (reset) { MGrid.Children.Clear(); } if (cmps == null) { return; } var sx = cmps.GetLength(0); var sy = cmps.GetLength(1); for (var i = 0; i < sx; i++) { for (var j = 0; j < sy; j++) { MGrid.Children.Add(cmps[i, j], i, j); } } }
// Do measurement when in horizontal orientation private void Measure(nfloat parentWidth, nfloat parentHeight) { // Work out our height nfloat layoutWidth = LayoutParameters.TryResolveWidth(this, parentWidth); nfloat layoutHeight = LayoutParameters.TryResolveHeight(this, parentHeight); // Work out the total fixed size var paddings = Padding.TotalWidth(); _goneViews = new List<View>(); _arrangedViews = new View[RowDefinitions.Count, ColumnDefinitions.Count]; var columnWidthFillParentSubviews = new List<View>(); //calculating columns var minWidth = (nfloat)ColumnDefinitions.Sum(x => x.MinWidth); foreach (var v in SubViews.Where(x=>!x.Gone)) { _arrangedViews[v.Row, v.Column] = v; var columnDefinition = ColumnDefinitions[v.Column]; var rowDefinition = RowDefinitions[v.Column]; nfloat width; if (columnDefinition.Width > 0) width = columnDefinition.Width; else if (columnDefinition.MaxWidth > 0) width = columnDefinition.MaxWidth; else width = parentWidth - paddings; nfloat height; if (rowDefinition.Height > 0) height = rowDefinition.Height; else height = adjustLayoutHeight(layoutHeight, v); if (v.LayoutParameters.WidthUnits != Units.ParentRatio) { v.Measure(width - v.LayoutParameters.Margins.TotalWidth(), height); } else { v._measuredSize = new CGSize(0, 0); v._measuredSizeValid = true; columnWidthFillParentSubviews.Add(v); } } { nfloat totalWeight = 0; nfloat totalWidth = 0; var columnId = -1; foreach (var column in ColumnDefinitions) { columnId++; column.CalculatedWidth = 0; if (column.Width > 0) { column.CalculatedWidth = column.Width; } else if (column.Width == AutoSize.WrapContent) { for (int rowId = 0; rowId < RowDefinitions.Count; rowId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { column.CalculatedWidth = NMath.Max(column.CalculatedWidth, v.GetMeasuredSize().Width + v.LayoutParameters.Margins.TotalWidth()); } } } else if (column.Width == AutoSize.FillParent) { totalWeight += column.Weight; } totalWidth += column.CalculatedWidth; } var room = layoutWidth - totalWidth; foreach (var column in ColumnDefinitions.Where(x => x.Width == AutoSize.FillParent)) { columnId++; column.CalculatedWidth = room * column.Weight / totalWeight; } } { var totalWeight = 0; var totalHeight = 0; var rowId = -1; foreach (var row in RowDefinitions) { rowId++; if (row.Height > 0) { row.CalculatedHeight = row.Height; continue; } if (row.Height == AutoSize.WrapContent) { row.CalculatedHeight = 0; for (int columnId = 0; columnId < ColumnDefinitions.Count; columnId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { row.CalculatedHeight = NMath.Max(row.CalculatedHeight, v.GetMeasuredSize().Height); } } } } var room = layoutHeight - totalHeight; foreach (var row in RowDefinitions.Where(x => x.Height == AutoSize.FillParent)) { row.CalculatedHeight = room * row.Weight / totalWeight; } } CGSize sizeMeasured = CGSize.Empty; foreach (var item in ColumnDefinitions) { sizeMeasured.Width += item.CalculatedWidth; } sizeMeasured.Width += ColSpacing * (ColumnDefinitions.Count - 1); foreach (var item in RowDefinitions) { sizeMeasured.Height += item.CalculatedHeight; } sizeMeasured.Height += RowSpacing * (RowDefinitions.Count - 1); foreach (var v in columnWidthFillParentSubviews) { v.Measure(ColumnDefinitions[v.Column].CalculatedWidth, RowDefinitions[v.Row].CalculatedHeight); } // And finally, set our measure dimensions SetMeasuredSize(LayoutParameters.ResolveSize(new CGSize(layoutWidth, layoutHeight), sizeMeasured)); }
public static IOrderedEnumerable <KeyValuePair <Tuple <double, double>, double> > GetHistResults(View[,] e1, View[,] e2) { var h1 = GetNumbersFromEntries(e1); var h2 = GetNumbersFromEntries(e2); var sx = h1.GetLength(0); var sy = h1.GetLength(1); var d = new Dictionary <Tuple <double, double>, double>(); for (var i = 0; i < sx; i++) { for (var j = 0; j < sy; j++) { var v1 = h1[i, j]; var v2 = h2[i, j]; var t = Tuple.Create(v2, v1); if (!d.ContainsKey(t)) { d.Add(t, 1); } else { d[t]++; } } } var en = d.OrderBy(pair => pair.Key.Item1).ThenBy(pair => pair.Key.Item2); return(en); }
// Do measurement when in horizontal orientation private void MeasureHorizontal(nfloat parentWidth, nfloat parentHeight) { // Work out our height nfloat layoutWidth = LayoutParameters.TryResolveWidth(this, parentWidth, parentHeight); nfloat layoutHeight = LayoutParameters.TryResolveHeight(this, parentWidth, parentHeight); // Work out the total fixed size var paddings = Padding.TotalWidth(); _goneViews = new List <View>(); _arrangedViews = new View[RowDefinitions.Count, ColumnDefinitions.Count]; var columnWidthFillParentSubviews = new List <View>(); //calculating columns var minWidth = (nfloat)ColumnDefinitions.Sum(x => x.MinWidth); foreach (var v in SubViews.Where(x => !x.Gone)) { _arrangedViews[v.Row, v.Column] = v; var columnDefinition = ColumnDefinitions[v.Column]; var rowDefinition = RowDefinitions[v.Column]; nfloat width; if (columnDefinition.Width > 0) { width = columnDefinition.Width; } else if (columnDefinition.MaxWidth > 0) { width = columnDefinition.MaxWidth; } else { width = parentWidth - paddings; } nfloat height; if (rowDefinition.Height > 0) { height = rowDefinition.Height; } else { height = adjustLayoutHeight(layoutHeight, v); } if (v.LayoutParameters.WidthUnits != Units.ParentRatio) { v.Measure(width - v.LayoutParameters.Margins.TotalWidth(), height); } else { v._measuredSize = new CGSize(0, 0); v._measuredSizeValid = true; columnWidthFillParentSubviews.Add(v); } } { nfloat totalWeight = 0; nfloat totalWidth = 0; var columnId = -1; foreach (var column in ColumnDefinitions) { columnId++; column.CalculatedWidth = 0; if (column.Width > 0) { column.CalculatedWidth = column.Width; } else if (column.Width == AutoSize.WrapContent) { for (int rowId = 0; rowId < RowDefinitions.Count; rowId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { column.CalculatedWidth = NMath.Max(column.CalculatedWidth, v.GetMeasuredSize().Width + v.LayoutParameters.Margins.TotalWidth()); } } } else if (column.Width == AutoSize.FillParent) { totalWeight += column.Weight; } totalWidth += column.CalculatedWidth; } var room = layoutWidth - totalWidth; foreach (var column in ColumnDefinitions.Where(x => x.Width == AutoSize.FillParent)) { columnId++; column.CalculatedWidth = room * column.Weight / totalWeight; } } { var totalWeight = 0; var totalHeight = 0; var rowId = -1; foreach (var row in RowDefinitions) { rowId++; if (row.Height > 0) { row.CalculatedHeight = row.Height; continue; } if (row.Height == AutoSize.WrapContent) { row.CalculatedHeight = 0; for (int columnId = 0; columnId < ColumnDefinitions.Count; columnId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { row.CalculatedHeight = NMath.Max(row.CalculatedHeight, v.GetMeasuredSize().Height); } } } } var room = layoutHeight - totalHeight; foreach (var row in RowDefinitions.Where(x => x.Height == AutoSize.FillParent)) { row.CalculatedHeight = room * row.Weight / totalWeight; } } CGSize sizeMeasured = CGSize.Empty; foreach (var item in ColumnDefinitions) { sizeMeasured.Width += item.CalculatedWidth; } sizeMeasured.Width += ColSpacing * (ColumnDefinitions.Count - 1); foreach (var item in RowDefinitions) { sizeMeasured.Height += item.CalculatedHeight; } sizeMeasured.Height += RowSpacing * (RowDefinitions.Count - 1); foreach (var v in columnWidthFillParentSubviews) { v.Measure(ColumnDefinitions[v.Column].CalculatedWidth, RowDefinitions[v.Row].CalculatedHeight); } // And finally, set our measure dimensions SetMeasuredSize(LayoutParameters.ResolveSize(new CGSize(layoutWidth, layoutHeight), sizeMeasured)); }