private void OnMeasureHorizontal(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style) { Operator.Measure(MeasureSpec.MakeUnspecified(), MeasureSpec.MakeUnspecified(), g, font, style); ActualOperator.Measure(MeasureSpec.MakeUnspecified(), MeasureSpec.MakeUnspecified(), g, font, style); MeasureSpec leftWidth = null; MeasureSpec rightWidth = null; if (widthSpec.Mode == MeasureSpecMode.Fixed) { leftWidth = MeasureSpec.MakeFixed((float)((widthSpec.Size - Operator.DesiredWidth) / 2)); rightWidth = MeasureSpec.MakeFixed((float)((widthSpec.Size - Operator.DesiredWidth) / 2)); } else if (widthSpec.Mode == MeasureSpecMode.AtMost) { leftWidth = MeasureSpec.MakeAtMost((float)((widthSpec.Size - Operator.DesiredWidth) / 2)); rightWidth = MeasureSpec.MakeAtMost((float)((widthSpec.Size - Operator.DesiredWidth) / 2)); } else if (widthSpec.Mode == MeasureSpecMode.Unspecified) { leftWidth = widthSpec; rightWidth = widthSpec; } Left.Measure(leftWidth, heightSpec, g, font, style); Right.Measure(rightWidth, heightSpec, g, font, style); isTwoLines = Left.DesiredWidth > 450 || Right.DesiredWidth > 450; if (!isTwoLines) { SetDesiredSize( Left.DesiredWidth + Right.DesiredWidth + GetOperatorWidth(), Math.Max(Left.FindMaxTop(), Right.FindMaxTop()) + Math.Max(Left.FindMaxBottom(), Right.FindMaxBottom())); } else { Operator = ActualOperator; SetDesiredSize( Math.Max(Left.DesiredWidth, Right.DesiredWidth + GetOperatorWidth()), Left.DesiredHeight + Math.Max(Operator.DesiredHeight, Right.DesiredHeight)); } }
protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style) { if (Rows.Length == 0) { SetDesiredSize(0, 0); return; } int rowCount = Rows.Length; int columnCount = Rows[0].Length; float spacing = 10; MeasureSpec cellWidth = MeasureSpec.MakeUnspecified(); MeasureSpec cellHeight = MeasureSpec.MakeUnspecified(); if (widthSpec.Mode == MeasureSpecMode.Fixed || widthSpec.Mode == MeasureSpecMode.AtMost) { cellWidth = MeasureSpec.MakeAtMost((widthSpec.Size - (columnCount + 1) * spacing) / columnCount); } if (heightSpec.Mode == MeasureSpecMode.Fixed || heightSpec.Mode == MeasureSpecMode.AtMost) { cellHeight = MeasureSpec.MakeAtMost((heightSpec.Size - (rowCount + 1) * spacing) / rowCount); } maxCellWidth = new float[columnCount]; maxCellTopHeight = new float[rowCount]; maxCellBottomHeight = new float[rowCount]; int rowIndex = 0; foreach (Expression[] row in Rows) { int columnIndex = 0; foreach (Expression item in row) { item.Measure(cellWidth, cellHeight, g, font, style); if (maxCellWidth[columnIndex] < item.DesiredWidth) { maxCellWidth[columnIndex] = item.DesiredWidth; } float topHeight = item.FindMaxTop(); float bottomHeight = item.FindMaxBottom(); if (maxCellTopHeight[rowIndex] < topHeight) { maxCellTopHeight[rowIndex] = topHeight; } if (maxCellBottomHeight[rowIndex] < bottomHeight) { maxCellBottomHeight[rowIndex] = bottomHeight; } columnIndex++; } rowIndex++; } SetDesiredSize( maxCellWidth.Sum() + (columnCount + 1) * spacing, maxCellTopHeight.Sum() + maxCellBottomHeight.Sum() + (rowIndex + 1) * spacing); }