//private void ApplyAlignment(FrameworkElement element, Thickness t, double x, double y, double w, double h) //{ // Rect rect = new Rect(x, y, element.Width, element.Height); // switch (element.HorizontalAlignment) // { // case HorizontalAlignment.Center: // rect.X = x + w / 2 - element.Width / 2; // break; // case HorizontalAlignment.Right: // rect.X = x + w - element.Width; // break; // case HorizontalAlignment.Stretch: // rect.Width = w - t.Right; // break; // } // switch (element.VerticalAlignment) // { // case VerticalAlignment.Center: // rect.Y = y + h / 2 - element.Height / 2; // break; // case VerticalAlignment.Bottom: // rect.Y = h - element.Height; // break; // case VerticalAlignment.Stretch: // rect.Height = h - t.Bottom; // break; // } // element.Arrange(rect); //} public void Arrange(GUIGroup element) { Point l = element.Location; Rect r = new Rect(); Thickness t = element.Margin; int index = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } double angle = (++index * 2 * Math.PI) / element.Children.Count; r.Width = child.Width; r.Height = child.Height; r.X = t.Left + _spacing.Width + ((_size.Width - t.Width - (_spacing.Width * 2)) / 2) + (int)(Math.Sin(angle) * _radius) - (r.Width / 2); r.Y = t.Top + _spacing.Height + ((_size.Height - t.Height - (_spacing.Height * 2)) / 2) - (int)(Math.Cos(angle) * _radius) - (r.Height / 2); child.Arrange(r); } }
public Size Measure(GUIGroup element, Size availableSize) { Thickness t = element.Margin; double tableContentHeight = 0; // Calculated overall table height less vertical spacing. int cols = _cols; // User specified number of table columns. int i = 0; // Index for retrieving child controls. int c = 1; // Current column number. double rowHeight = 0d; // Current row height. GUIControl child; Cell TableCell; while (i < element.Children.Count) { c = 1; while (c <= cols) { if (i >= element.Children.Count) { break; // Bailout if we run out of controls while looking at the last row. } child = element.Children[i]; if (child.Visibility == Visibility.Collapsed) { i++; // Advance to the next control. continue; } // Get the table cell details for this child. TableCell = GetCell((GUIControl)child); if (TableCell.TargetCol > 0 && TableCell.TargetCol < c) { // We have passed the target column in this row. // Advance to the next row. c = cols + 1; continue; } if (TableCell.TargetCol > c) { // Advance to the specified column. c = TableCell.TargetCol; } child.Measure(availableSize); rowHeight = Math.Max(rowHeight, (double)child.Height * TableCell.RowSpan); // Advance column index according to specified column span. c += TableCell.ColSpan - 1; // Columns with no span specify the exact desired width of the column. if (TableCell.ColSpan == 1) { ((Column)_columns[c - 1]).width = (double)child.Width; ((Column)_columns[c - 1]).isCalculated = false; } i++; // Advance to the next control. c++; // Advance to the next column. } // Recalculate column width for each column with unspecified width. double span = 0; int count = 0; foreach (Column col in _columns) { if (!col.isCalculated) { span += col.width; count++; } } if (count > 0) { span = (_width - span) / (cols - count); foreach (Column col in _columns) { if (col.isCalculated) { col.width = span; } } } tableContentHeight += rowHeight; _rowHeight.Add(rowHeight); // Store the row height. rowHeight = 0; // Reset for next row. } // for (int x = 0; x <= _columns.Count - 1; x++) // { // Log.Info("TableLayout.Measure: columns[{0}]={1}, calc={2}", x, ((Column)_columns[x]).width, ((Column)_columns[x]).isCalculated); // } _size.Width = _width; // Table is fixed width. _size.Height = (tableContentHeight + _spacing.Height * (_rowHeight.Count - 1)) + t.Height; return _size; }
public void Arrange(GUIGroup element) { Thickness t = element.Margin; int rows = _rowHeight.Count; // Calculated number of table rows. int cols = _cols; // User specified number of table columns. int i = 0; // Index for retrieving child controls. GUIControl child; Cell TableCell; double x = element.Location.X + t.Left; double y = element.Location.Y + t.Top; double w = 0; double h = 0; double ch = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { if (i >= element.Children.Count) { break; // Bailout if we run out of controls while looking at the last row. } child = element.Children[i]; if (child.Visibility == Visibility.Collapsed) { i++; // Advance to the next control. continue; } // Get the table cell details for this child. TableCell = GetCell((GUIControl)child); // If the target column is not the current column then move the x position to the target column position. // A target column value of 0 indicates no target column preference is set. if (TableCell.TargetCol > 0 && c != TableCell.TargetCol - 1) { // Check whether the target column in the current row. if (c < TableCell.TargetCol - 1) // Target column value is 1-based. { for (int a = c; a < TableCell.TargetCol - 1; a++) { x += ((Column)_columns[a]).width + _spacing.Width; } c = TableCell.TargetCol - 1; } else if (TableCell.TargetCol - 1 >= 0) { // Advance to the next row to set the target column. c = cols; continue; } } if (TableCell.ColSpan > 1) { // When spanning columns we must add the spacing. w = 0; for (int a = c; a <= c + TableCell.ColSpan - 1; a++) { w += ((Column)_columns[a]).width + _spacing.Width; // Log.Info("TableLayout.Arrange: spanning spanWidth={0:0.000}, colWidth={1:0.000}, w={2:0.000}", _spacing.Width, ((Column)_columns[a]).width, w); } w -= _spacing.Width; } else { w = ((Column)_columns[c]).width; // Log.Info("TableLayout.Arrange: w={0:0.000}", w); } h = (double)_rowHeight[r]; ch = child.Height * TableCell.RowSpan; //Log.Info("TableLayout.Arrange: (c={0}, r={1}) x={2:0.000},y={3:0.000},w={4:0.000}", c + 1, r + 1, x, y, w); ApplyAlignment(child, t, x, y, w, ch); // Move to the last column in the span. c += TableCell.ColSpan - 1; // Move to the start of the next column. x += w + _spacing.Width; i++; // Advance to the next control. } x = element.Location.X + t.Left; y += h + _spacing.Height; } }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = Math.Max(w, child.Width); h = Math.Max(h, child.Height); } Thickness t = element.Margin; _radius = (Math.Min(w + _spacing.Width * element.Children.Count, h + _spacing.Height * element.Children.Count) / 2); _radius -= Math.Max(w, h) / 2; _size.Width = (int)(2 * _radius) - w + t.Width; _size.Height = (int)(2 * _radius) - h + t.Height; return _size; }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; int rows = _rows; int cols = _cols; if (rows > 0) { cols = (element.Children.Count + rows - 1) / rows; } else { rows = (element.Children.Count + cols - 1) / cols; } foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = Math.Max(w, child.Width); h = Math.Max(h, child.Height); } Thickness t = element.Margin; _size.Width = (w * cols + _spacing.Width * (cols - 1)) + t.Width; _size.Height = (h * rows + _spacing.Height * (rows - 1)) + t.Height; return _size; }
public void Arrange(GUIGroup element) { Point location = element.Location; Thickness t = element.Margin; int rows = _rows; int cols = _cols; if (rows > 0) { cols = (element.Children.Count + rows - 1) / rows; } else { rows = (element.Children.Count + cols - 1) / cols; } double w = (element.Width - t.Width - (cols - 1) * _spacing.Width) / cols; double h = (element.Height - t.Height - (rows - 1) * _spacing.Height) / rows; double y = element.Location.Y + t.Top; for (int row = 0; row < rows; row++) { double x = element.Location.X + t.Left; for (int col = 0; col < cols; col++) { int index = _orientation == Orientation.Vertical ? col * rows + row : row * cols + col; if (index < element.Children.Count) { var component = element.Children[index]; if (component.Visibility == Visibility.Collapsed) { continue; } ApplyAlignment(component, t, x, y, w, h); } x += w + _spacing.Width; } y += h + _spacing.Height; } }
public void Arrange(GUIGroup element) { Thickness t = element.Margin; Point l = element.Location; double x = element.Location.X + t.Left; double y = element.Location.Y + t.Top; double w = _orientation != Orientation.Horizontal ? Math.Max(0, element.Width - t.Width) : 0; double h = _orientation == Orientation.Horizontal ? Math.Max(0, element.Height - t.Height) : 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } if (_orientation == Orientation.Horizontal) { ApplyAlignment(child, t, x, y, w = child.Width, h); x += w + _spacing.Width; continue; } ApplyAlignment(child, t, x, y, w, h = child.Height); y += h + _spacing.Height; } }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = _orientation != Orientation.Horizontal ? Math.Max(w, child.Width) : w + child.Width + _spacing.Width; h = _orientation == Orientation.Horizontal ? Math.Max(h, child.Height) : h + child.Height + _spacing.Height; } Thickness t = element.Margin; _size.Width = w + t.Width; _size.Height = h + t.Height; return _size; }