예제 #1
0
        public override void Arrange(IFigure parent)
        {
            var clientArea = _padding.GetClientArea(parent.Bounds);
            var constraint = new SizeConstraint(clientArea.Size);

            var itemTop = parent.Top + _padding.Top;

            foreach (var child in parent.Children)
            {
                if (child.IsVisible)
                {
                    var csize = child.PreferredSize;
                    child.Location = new Point(parent.Left + _padding.Left, itemTop);
                    if (_adjustItemWidth)
                    {
                        child.Width = clientArea.Width;
                    }
                    child.Height = csize.Height;
                    itemTop     += child.Height + ItemSpace;
                }
            }

            if (_extendLast && parent.Children.Count > 0)
            {
                /// 最後のchildを残りいっぱいの大きさにする
                var lastItem = parent.Children.Last();
                lastItem.Height = clientArea.Bottom - lastItem.Top;
            }
        }
예제 #2
0
        public override void Arrange(IFigure parent)
        {
            var clientArea = _padding.GetClientArea(parent.Bounds);
            var constraint = new SizeConstraint(clientArea.Size);

            /// childrenを行に分割,各行とそのwidth,heightを保持
            var lines = new List <Tuple <List <IFigure>, int, int> >();
            {
                List <IFigure> line    = null;
                var            cWidth  = 0;
                var            cHeight = 0;
                foreach (var child in parent.Children)
                {
                    if (child.IsVisible)
                    {
                        var cSize = Size.Empty;
                        if (_adjustChildrenSize)
                        {
                            child.Measure(constraint);
                            cSize = child.PreferredSize;
                        }
                        else
                        {
                            cSize = child.Size;
                        }

                        if (cWidth + cSize.Width + _hGap >= clientArea.Width)
                        {
                            lines.Add(Tuple.Create(line, cWidth, cHeight));
                            line    = null;
                            cWidth  = 0;
                            cHeight = 0;
                        }

                        if (line == null)
                        {
                            line = new List <IFigure>();
                            line.Add(child);
                            cWidth  = cSize.Width + _padding.Width;
                            cHeight = cSize.Height;
                        }
                        else
                        {
                            line.Add(child);
                            cWidth += cSize.Width + _hGap;
                            cHeight = Math.Max(cHeight, cSize.Height);
                        }
                    }
                }
                if (line != null)
                {
                    lines.Add(Tuple.Create(line, cWidth, cHeight));
                }
            }

            var cLeft = clientArea.Left + _padding.Left;
            var cTop  = clientArea.Top + _padding.Top;

            foreach (var line in lines)
            {
                var figs   = line.Item1;
                var width  = line.Item2;
                var height = line.Item3;
                foreach (var fig in figs)
                {
                    fig.Location = new Point(cLeft, cTop);
                    if (_adjustChildrenSize)
                    {
                        var pSize = fig.PreferredSize;
                        fig.Size = new Size(Math.Min(pSize.Width, clientArea.Width), pSize.Height);
                    }
                    cLeft += fig.Width + _hGap;
                }
                cTop += height + _vGap;
            }
        }