Ejemplo n.º 1
0
 public LineBoxesContext(CustomRenderBox owner)
 {
     //set owner element if we want to preserver linebox ***
     _owner   = owner;
     _context = LayoutTools.BorrowList(out _lineboxes);
     _sharedLineBoxContextListContext = LayoutTools.BorrowList(out _sharedLineBoxContexts);
 }
Ejemplo n.º 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;//**
                }
            }
        }
Ejemplo n.º 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);
                        }
                    }
        }