Beispiel #1
0
        static void AlignLeftToRight(List <IAbstractRect> boxes, int x_pos)
        {
            int j = boxes.Count;

            for (int i = 0; i < j; ++i)
            {
                IAbstractRect r = boxes[i];
                x_pos += r.MarginLeft;
                r.SetLocation(x_pos, r.Top);
                x_pos += r.Width + r.MarginRight;
            }
        }
Beispiel #2
0
        public void AdjustVerticalAlignment()
        {
            using (LayoutTools.BorrowList(out List <IAbstractRect> expandables))
            {
                LinkedListNode <IAbstractRect> node = _linkList.First;

                while (node != null)
                {
                    IAbstractRect r = node.Value;
                    if (!r.HasSpecificHeight)
                    {
                        //expand to full fit
                        r.SetLocationAndSize(r.Left, r.MarginTop, r.Width, LineHeight - (r.MarginTop + r.MarginBottom));
                    }
                    else
                    {
                        //has specific height

                        switch (r.VerticalAlignment)
                        {
                        case VerticalAlignment.Top:

                            r.SetLocation(r.Left, r.MarginTop);
                            break;

                        case VerticalAlignment.Bottom:
                        {
                            int diff = LineHeight - (r.Height + r.MarginTop);
                            if (diff > 0)
                            {
                                r.SetLocation(r.Left, r.Top + diff);
                            }
                        }
                        break;

                        case VerticalAlignment.Middle:
                        {
                            int diff = LineHeight - (r.Height + r.MarginTop);
                            if (diff > 0)
                            {
                                r.SetLocation(r.Left, r.Top + (diff / 2));
                            }
                        }
                        break;
                        }
                    }
                    node = node.Next;//**
                }
            }
        }
Beispiel #3
0
        public void AdjustHorizontalAlignment(int limitW)
        {
            //line, and spread data inside this line

            //expand...
            using (LayoutTools.BorrowList(out List <IAbstractRect> expandables))
                using (LayoutTools.BorrowList(out List <IAbstractRect> middleAlignments))
                    using (LayoutTools.BorrowList(out List <IAbstractRect> rigthAlignments))
                    {
                        LinkedListNode <IAbstractRect> node = _linkList.First;
                        if (_maxRight < limitW)
                        {
                            while (node != null)
                            {
                                IAbstractRect r = node.Value;
                                if (!r.HasSpecificWidth)
                                {
                                    //expand candidate
                                    expandables.Add(r);
                                }
                                node = node.Next;//**
                            }
                            int count = expandables.Count;
                            if (count > 0)
                            {
                                int availableLen = limitW - _maxRight;
                                int avg          = availableLen / count;

                                for (int i = 0; i < count; ++i)
                                {
                                    IAbstractRect exp = expandables[i];
                                    exp.SetSize(exp.Width + avg, exp.Height);
                                }
                            }
                        }
                        //-----------------------
                        //now distribute the remaining width to expandable elements

                        //do horizontal alignment again if we have some change
                        node = _linkList.First;

                        int x_pos = 0;
                        int total_right_align_w  = 0;
                        int total_middle_align_w = 0;


                        int             node_no         = 0;
                        RectUIAlignment latestAlignment = RectUIAlignment.Begin;
                        while (node != null)
                        {
                            IAbstractRect r = node.Value;
                            switch (r.HorizontalAlignment)
                            {
                            case RectUIAlignment.Begin:
                            {
                                x_pos += r.MarginLeft;
                                r.SetLocation(x_pos, r.Top); //same y pos
                                x_pos += r.Width + r.MarginRight;
                            }
                            break;

                            case RectUIAlignment.Middle:
                            {
                                middleAlignments.Add(r);
                                total_middle_align_w += r.Width + r.MarginLeft + r.MarginRight;
                            }
                            break;

                            case RectUIAlignment.End:
                            {
                                rigthAlignments.Add(r);
                                total_right_align_w += r.Width + r.MarginLeft + r.MarginRight;
                            }
                            break;
                            }

                            if (node_no > 0 && latestAlignment != r.HorizontalAlignment)
                            {
                                _mixedHorizontalAlignment = true;
                            }
                            latestAlignment = r.HorizontalAlignment;

                            node = node.Next;//**
                            node_no++;
                        }
                        //-----------------------
                        if (rigthAlignments.Count > 0)
                        {
                            AlignLeftToRight(rigthAlignments, limitW - total_right_align_w);
                        }
                        if (middleAlignments.Count > 0)
                        {
                            AlignLeftToRight(middleAlignments, (limitW - total_middle_align_w) / 2);
                        }
                    }
        }
Beispiel #4
0
 public void Add(IAbstractRect renderE)
 {
     _linkList.AddLast(renderE);
     _maxRight = renderE.Width + renderE.Left + renderE.MarginRight;
 }