Exemplo n.º 1
0
        private void OnMeasureDivide(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            MeasureSpec leftHeight  = null;
            MeasureSpec rightHeight = null;

            if (heightSpec.Mode == MeasureSpecMode.Fixed)
            {
                leftHeight  = MeasureSpec.MakeFixed((float)((heightSpec.Size - 2) / 2));
                rightHeight = MeasureSpec.MakeFixed((float)((heightSpec.Size - 2) / 2));
            }
            else if (heightSpec.Mode == MeasureSpecMode.AtMost)
            {
                leftHeight  = MeasureSpec.MakeAtMost((float)((heightSpec.Size - 2) / 2));
                rightHeight = MeasureSpec.MakeAtMost((float)((heightSpec.Size - 2) / 2));
            }
            else if (heightSpec.Mode == MeasureSpecMode.Unspecified)
            {
                leftHeight  = heightSpec;
                rightHeight = heightSpec;
            }

            Left.Measure(widthSpec, leftHeight, g, font, style);
            Right.Measure(widthSpec, rightHeight, g, font, style);


            Operator.Measure(MeasureSpec.MakeFixed(Math.Max(Left.DesiredWidth, Right.DesiredWidth) + 10), MeasureSpec.MakeFixed(2), g, font, style);


            SetDesiredSize(Math.Max(Left.DesiredWidth, Right.DesiredWidth) + 10, Left.DesiredHeight + Right.DesiredHeight + Operator.DesiredHeight);
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            float desiredWidth;

            if (widthSpec.Mode != MeasureSpecMode.Unspecified)
            {
                float width = SigmaWidth * Sigmas.Length + 5 * (Sigmas.Length - 1);
                Operand.Measure(MeasureSpec.MakeAtMost(widthSpec.Size - width), heightSpec, g, font, style);
                width += Operand.DesiredWidth;

                if (widthSpec.Mode == MeasureSpecMode.Fixed)
                {
                    desiredWidth = widthSpec.Size;
                }
                else
                {
                    desiredWidth = width;
                }
            }
            else
            {
                desiredWidth = 0;

                foreach (SigmaConfig sigma in Sigmas)
                {
                    if (sigma.From != null)
                    {
                        sigma.From.Measure(widthSpec, heightSpec, g, style.SmallFont, style);
                        sigma.To.Measure(widthSpec, heightSpec, g, style.SmallFont, style);
                        desiredWidth += Math.Max(SigmaWidth, Math.Max(sigma.From.DesiredWidth, sigma.To.DesiredWidth));
                    }
                }

                desiredWidth += 5 * (Sigmas.Length - 1);

                Operand.Measure(widthSpec, heightSpec, g, font, style);
                desiredWidth += Operand.DesiredWidth;
            }


            SetDesiredSize((float)desiredWidth,
                           Math.Max(SigmaHeight / 2 + Sigmas.Max(i => i.From == null ? 0 : i.From.DesiredHeight), Operand.FindMaxBottom()) +
                           Math.Max(SigmaHeight / 2 + Sigmas.Max(i => i.To == null ? 0 : i.To.DesiredHeight), Operand.FindMaxTop()) + 6);
        }
Exemplo n.º 4
0
        protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            SizeF limSize = g.MeasureString("lim", font);

            float width;

            if (widthSpec.Mode != MeasureSpecMode.Unspecified)
            {
                MeasureSpec spec = MeasureSpec.MakeAtMost((widthSpec.Size - 10) / 2);
                X.Measure(spec, heightSpec, g, style.SmallFont, style);
                Limit.Measure(spec, heightSpec, g, style.SmallFont, style);


                float leftWidth = Math.Max(X.DesiredWidth + Limit.DesiredWidth + 10, limSize.Width);
                Body.Measure(MeasureSpec.MakeAtMost(widthSpec.Size - leftWidth), heightSpec, g, font, style);

                if (widthSpec.Mode == MeasureSpecMode.Fixed)
                {
                    width = widthSpec.Size;
                }
                else
                {
                    width = Math.Min(leftWidth + Body.DesiredWidth, widthSpec.Size);
                }
            }
            else
            {
                X.Measure(widthSpec, heightSpec, g, font, style);
                Limit.Measure(widthSpec, heightSpec, g, font, style);
                Body.Measure(widthSpec, heightSpec, g, font, style);

                width = Math.Max(X.DesiredWidth + Limit.DesiredWidth + 10, limSize.Width) + Body.DesiredWidth;
            }

            SetDesiredSize(width, Math.Max(Math.Max(X.DesiredHeight, Limit.DesiredHeight) + limSize.Height, Body.DesiredHeight));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            float desiredWidth;

            nameSize = g.MeasureString(Name + "(", font);

            if (widthSpec.Mode != MeasureSpecMode.Unspecified)
            {
                float width = g.MeasureString(Name + "(", font).Width;

                float index = 0;

                foreach (Expression operand in Operands)
                {
                    operand.Measure(MeasureSpec.MakeAtMost(widthSpec.Size), heightSpec, g, font, style);
                    float puncWidth = g.MeasureString(index == Operands.Length - 1 ? ")" : ",", font).Width;

                    if (width + operand.DesiredWidth + puncWidth > widthSpec.Size)
                    {
                        operand.Measure(MeasureSpec.MakeAtMost(widthSpec.Size - width), heightSpec, g, font, style);
                        break;
                    }


                    width += operand.DesiredWidth + puncWidth;

                    index++;
                }

                if (widthSpec.Mode == MeasureSpecMode.Fixed)
                {
                    desiredWidth = widthSpec.Size;
                }
                else
                {
                    desiredWidth = width;
                }
            }
            else
            {
                desiredWidth = g.MeasureString(Name + "(", font).Width;

                float index = 0;

                foreach (Expression operand in Operands)
                {
                    operand.Measure(widthSpec, heightSpec, g, font, style);

                    float puncWidth = g.MeasureString(index == Operands.Length - 1 ? ")" : ",", font).Width;
                    desiredWidth += operand.DesiredWidth + puncWidth;

                    index++;
                }
            }


            if (desiredWidth <= 300)
            {
                SetDesiredSize(desiredWidth, Math.Max(g.MeasureString(Name, font).Height, Operands.Length == 0 ? 0 : Operands.Max(i => i.FindMaxTop()) + Operands.Max(i => i.FindMaxBottom())));
            }
            else
            {
                SetDesiredSize(Operands.Max(i => i.DesiredWidth) + g.MeasureString(",", font).Width + 50, g.MeasureString(Name + "(", font).Height + g.MeasureString(")", font).Height + Operands.Sum(i => i.DesiredHeight));
                isMultiLine = true;
            }
        }