/// <summary> /// Delete compoenent from the rung /// </summary> /// <param name="component">Component to be deleted</param> public RungUI Remove(ComponentUIBase component) { ComponentGridPosition _component = _Components.Where(x => x.Component == component).First(); if (_LogicalRung.Components.Where(x => x.LeftLide == component.LogicComponent.LeftLide && x.RightLide == component.LogicComponent.RightLide).Count() > 1) { foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row)) { item.SetPossition(item.Row - 1, item.Column); } } else { IEnumerable <ComponentGridPosition> RR = _Components.Where(x => x.Component.LogicComponent.RightLide == component.LogicComponent.RightLide && x != _component); if (RR.Count() > 0) { IEnumerable <ComponentGridPosition> column_components = _Components.Where(x => x.Column == _component.Column); if (column_components.Count() == 1) { foreach (ComponentGridPosition item in _Components.Where(x => x.Column > _component.Column)) { item.SetPossition(item.Row, item.Column - 1); } } else { foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row)) { item.SetPossition(item.Row - 1, item.Column); } } } else { foreach (ComponentGridPosition item in _Components.Where(x => x.Component.LogicComponent.LeftLide == component.LogicComponent.RightLide)) { item.SetPossition(item.Row, item.Column - 1); } } } _Components.Remove(_component); _LogicalRung.Remove(component.LogicComponent); Children.Remove(component); var row = RowDefinitions.Where(x => _Components.Where(y => (y.Row == RowDefinitions.IndexOf(x))).Count() == 0); if (row.Count() != 0) { int row_index = RowDefinitions.IndexOf(row.First()); foreach (ComponentGridPosition item in _Components.Where(x => x.Row > row_index)) { item.SetPossition(item.Row - 1, item.Column); } RowDefinitions.RemoveAt(row_index); } var column = ColumnDefinitions.Where(x => _Components.Where(y => (y.Column == ColumnDefinitions.IndexOf(x))).Count() == 0); if (column.Count() != 0) { int column_index = ColumnDefinitions.IndexOf(column.First()); if (_component.Column >= ColumnDefinitions.Count - _OutputBlockLegth) { _OutputBlockLegth--; } foreach (ComponentGridPosition item in _Components.Where(x => x.Column > column_index)) { item.SetPossition(item.Row, item.Column - 1); } ColumnDefinitions.RemoveAt(column_index); } return(this); }
// 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)); }