예제 #1
0
        /*
         * Align elements horizontally and return a canvas.
         * Elements include Canvas and MathText.
         */
        public AlignCanvas ArrangeHorizontalGroup(params FrameworkElement[] elements)
        {
            AlignCanvas board = new AlignCanvas();
            //  maxAlignDepth: the max depth from the top, where all nodes are to be aligned
            double startWidth = 0, maxAlignDepth = 0;

            // set each element's left margin
            foreach (var element in elements)
            {
                AlignCanvas.SetLeft(element, startWidth);
                if (element is MathText)
                {
                    element.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                    startWidth += element.DesiredSize.Width;
                    if (maxAlignDepth < element.DesiredSize.Height / 2)
                    {
                        maxAlignDepth = element.DesiredSize.Height / 2;
                    }
                }
                else
                {
                    // it's a canvas.
                    startWidth += element.Width;
                    if (maxAlignDepth < (element as AlignCanvas).alignHeight)
                    {
                        maxAlignDepth = (element as AlignCanvas).alignHeight;
                    }
                }
            }

            // set each element's top margin
            double maxDepth = 0;

            foreach (var element in elements)
            {
                if (element is MathText)
                {
                    AlignCanvas.SetTop(element, maxAlignDepth - element.DesiredSize.Height / 2);
                    if (element.DesiredSize.Height + maxAlignDepth - element.DesiredSize.Height / 2 > maxDepth)
                    {
                        maxDepth = element.DesiredSize.Height + maxAlignDepth - element.DesiredSize.Height / 2;
                    }
                }
                else
                {
                    AlignCanvas.SetTop(element, maxAlignDepth - (element as AlignCanvas).alignHeight);
                    if (element.Height + maxAlignDepth - (element as AlignCanvas).alignHeight > maxDepth)
                    {
                        maxDepth = element.Height + maxAlignDepth - (element as AlignCanvas).alignHeight;
                    }
                }
                board.Children.Add(element);
            }
            board.Width       = startWidth;
            board.Height      = maxDepth;
            board.alignHeight = maxAlignDepth;
            return(board);
        }
예제 #2
0
        public AlignCanvas ArrangeVerticalGroup(params FrameworkElement[] elements)
        {
            AlignCanvas board = new AlignCanvas();
            double      startDepth = 0, maxWidth = 0;

            // set each element's left margin
            foreach (var element in elements)
            {
                AlignCanvas.SetTop(element, startDepth);
                if (element is Rectangle) // fraction bar
                {
                    board.alignHeight = startDepth;
                }
                if (element is MathText)
                {
                    element.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                    startDepth += element.DesiredSize.Height;
                    if (maxWidth < element.DesiredSize.Width)
                    {
                        maxWidth = element.DesiredSize.Width;
                    }
                }
                else
                {
                    // it's a canvas or sth like that.
                    startDepth += element.Height;
                    if (maxWidth < element.Width)
                    {
                        maxWidth = element.Width;
                    }
                }
            }

            // set each element's top margin
            foreach (var element in elements)
            {
                if (element is MathText)
                {
                    AlignCanvas.SetLeft(element, (maxWidth - element.DesiredSize.Width) / 2);
                }
                else
                {
                    AlignCanvas.SetLeft(element, (maxWidth - element.Width) / 2);
                }
                board.Children.Add(element);
            }
            board.Height = startDepth;
            board.Width  = maxWidth;
            if (board.alignHeight == 0)
            {
                board.alignHeight = startDepth;
            }
            return(board);
        }