Example #1
0
        public void InsertRow(int top, int bottom)
        {
            var potentials = children.Where(c => c.Top >= top);
            var shift      = bottom - top;

            foreach (var toShift in potentials)
            {
                toShift.Top    += shift;
                toShift.Bottom += shift;
            }
        }
Example #2
0
        protected override void OnReallocate()
        {
            var size = Backend.Size;
            var mode = ((IWidgetSurface)this).SizeRequestMode;

            if (mode == SizeRequestMode.HeightForWidth)
            {
                CalcDefaultSizes(mode, size.Width, false, true);
                CalcDefaultSizes(mode, size.Height, true, true);
            }
            else
            {
                CalcDefaultSizes(mode, size.Height, true, true);
                CalcDefaultSizes(mode, size.Width, false, true);
            }

            var visibleChildren = children.Where(c => c.Child.Visible).ToArray();

            IWidgetBackend[] widgets = new IWidgetBackend [visibleChildren.Length];
            Rectangle[]      rects   = new Rectangle [visibleChildren.Length];
            for (int n = 0; n < visibleChildren.Length; n++)
            {
                var bp = visibleChildren [n];
                widgets [n] = (IWidgetBackend)GetBackend(bp.Child);
                rects [n]   = new Rectangle(bp.NextX, bp.NextY, bp.NextWidth, bp.NextHeight);
            }

            Backend.SetAllocation(widgets, rects);

            if (!Application.EngineBackend.HandlesSizeNegotiation)
            {
                foreach (var bp in visibleChildren)
                {
                    ((IWidgetSurface)bp.Child).Reallocate();
                }
            }
        }
Example #3
0
File: Box.cs Project: wesreid/xwt
        protected override void OnReallocate()
        {
            var size = Backend.Size;

            if (size.Width <= 0 || size.Height <= 0)
            {
                return;
            }

            var visibleChildren = children.Where(c => c.Child.Visible).ToArray();

            IWidgetBackend[] widgets = new IWidgetBackend [visibleChildren.Length];
            Rectangle[]      rects   = new Rectangle [visibleChildren.Length];

            if (direction == Orientation.Horizontal)
            {
                CalcDefaultSizes(size.Width, size.Height);
                double xs = 0;
                double xe = size.Width + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var    bp             = visibleChildren [n];
                    double availableWidth = bp.NextSize >= 0 ? bp.NextSize : 0;
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        xe -= availableWidth + spacing;
                    }

                    var slot = new Rectangle(bp.PackOrigin == PackOrigin.Start ? xs : xe, 0, availableWidth, size.Height);
                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = bp.Child.Surface.GetPlacementInRect(slot).Round().WithPositiveSize();

                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        xs += availableWidth + spacing;
                    }
                }
            }
            else
            {
                CalcDefaultSizes(size.Width, size.Height);
                double ys = 0;
                double ye = size.Height + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var    bp = visibleChildren [n];
                    double availableHeight = bp.NextSize >= 0 ? bp.NextSize : 0;
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        ye -= availableHeight + spacing;
                    }

                    var slot = new Rectangle(0, bp.PackOrigin == PackOrigin.Start ? ys : ye, size.Width, availableHeight);
                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = bp.Child.Surface.GetPlacementInRect(slot).Round().WithPositiveSize();

                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        ys += availableHeight + spacing;
                    }
                }
            }
            Backend.SetAllocation(widgets, rects);

            if (!BackendHost.EngineBackend.HandlesSizeNegotiation)
            {
                foreach (var bp in visibleChildren)
                {
                    bp.Child.Surface.Reallocate();
                }
            }
        }
Example #4
0
File: Box.cs Project: Clancey/xwt
        protected override void OnReallocate()
        {
            var size = Backend.Size;

            var visibleChildren = children.Where(c => c.Child.Visible).ToArray();

            IWidgetBackend[] widgets = new IWidgetBackend [visibleChildren.Length];
            Rectangle[]      rects   = new Rectangle [visibleChildren.Length];

            if (direction == Orientation.Horizontal)
            {
                CalcDefaultSizes(Surface.SizeRequestMode, size.Width, size.Height);
                double xs = 0;
                double xe = size.Width + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var bp = visibleChildren [n];
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        xe -= bp.NextSize + spacing;
                    }
                    double x = bp.PackOrigin == PackOrigin.Start ? xs : xe;
                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = new Rectangle(x, 0, bp.NextSize, size.Height);
                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        xs += bp.NextSize + spacing;
                    }
                }
            }
            else
            {
                CalcDefaultSizes(Surface.SizeRequestMode, size.Height, size.Width);
                double ys = 0;
                double ye = size.Height + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var bp = visibleChildren [n];
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        ye -= bp.NextSize + spacing;
                    }
                    double y = bp.PackOrigin == PackOrigin.Start ? ys : ye;
                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = new Rectangle(0, y, size.Width, bp.NextSize);
                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        ys += bp.NextSize + spacing;
                    }
                }
            }
            Backend.SetAllocation(widgets, rects);

            if (!Application.EngineBackend.HandlesSizeNegotiation)
            {
                foreach (var bp in visibleChildren)
                {
                    bp.Child.Surface.Reallocate();
                }
            }
        }
Example #5
0
        void CalcDefaultSizes(SizeRequestMode mode, double totalSize, double lengthConstraint)
        {
            bool   calcHeights         = direction == Orientation.Vertical;
            bool   useLengthConstraint = mode == SizeRequestMode.HeightForWidth && calcHeights || mode == SizeRequestMode.WidthForHeight && !calcHeights;
            int    nexpands            = 0;
            double naturalSize         = 0;

            var visibleChildren = children.Where(b => b.Child.Visible);
            int childrenCount   = 0;

            // Get the natural size of each child
            foreach (var bp in visibleChildren)
            {
                childrenCount++;
                WidgetSize s;
                if (useLengthConstraint)
                {
                    s = GetPreferredLengthForSize(mode, bp.Child, lengthConstraint);
                }
                else
                {
                    s = GetPreferredSize(calcHeights, bp.Child);
                }
                naturalSize += s.NaturalSize;
                bp.NextSize  = s.NaturalSize;
                if ((bp.BoxMode & BoxMode.Expand) != 0)
                {
                    nexpands++;
                }
            }

            double remaining = totalSize - naturalSize - (spacing * (double)(childrenCount - 1));

            if (remaining < 0)
            {
                // The box is not big enough to fit the widgets using its natural size.
                // We have to shrink the widgets.
                var    sizePart   = new SizeSplitter(-remaining, childrenCount);
                var    toAdjust   = new List <BoxPlacement> ();
                double adjustSize = 0;
                foreach (var bp in visibleChildren)
                {
                    WidgetSize s;
                    if (useLengthConstraint)
                    {
                        s = GetPreferredLengthForSize(mode, bp.Child, lengthConstraint);
                    }
                    else
                    {
                        s = GetPreferredSize(calcHeights, bp.Child);
                    }
                    bp.NextSize = s.NaturalSize - sizePart.NextSizePart();
                    if (bp.NextSize < s.MinSize)
                    {
                        adjustSize += (s.MinSize - bp.NextSize);
                        bp.NextSize = s.MinSize;
                    }
                    else
                    {
                        toAdjust.Add(bp);
                    }
                }
                sizePart = new SizeSplitter(adjustSize, toAdjust.Count);
                foreach (var bp in toAdjust)
                {
                    bp.NextSize += sizePart.NextSizePart();
                }
            }
            else
            {
                var expandRemaining = new SizeSplitter(remaining, nexpands);
                foreach (var bp in visibleChildren)
                {
                    if ((bp.BoxMode & BoxMode.Expand) != 0)
                    {
                        bp.NextSize += expandRemaining.NextSizePart();
                    }
                }
            }
        }
Example #6
0
        protected override void OnReallocate()
        {
            var size = Backend.Size;

            if (size.Width <= 0 || size.Height <= 0)
            {
                return;
            }

            var visibleChildren = children.Where(c => c.Child.Visible).ToArray();

            IWidgetBackend[] widgets = new IWidgetBackend [visibleChildren.Length];
            Rectangle[]      rects   = new Rectangle [visibleChildren.Length];

            if (direction == Orientation.Horizontal)
            {
                CalcDefaultSizes(size.Width, size.Height);
                double xs = 0;
                double xe = size.Width + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var bp = visibleChildren [n];
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        xe -= bp.NextSize + spacing;
                    }

                    double width  = bp.NextSize >= 0 ? bp.NextSize : 0;
                    double height = size.Height - bp.Child.Margin.VerticalSpacing;
                    if (bp.Child.VerticalPlacement != WidgetPlacement.Fill)
                    {
                        height = Math.Min(bp.Child.Surface.GetPreferredSize(width, SizeConstraint.Unconstrained).Height, height);
                    }
                    double x = bp.PackOrigin == PackOrigin.Start ? xs : xe;
                    double y = (size.Height - bp.Child.Margin.VerticalSpacing - height) * bp.Child.VerticalPlacement.GetValue();

                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = new Rectangle(x + bp.Child.MarginLeft, y + bp.Child.MarginTop, width, height).Round().WithPositiveSize();
                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        xs += bp.NextSize + bp.Child.Margin.HorizontalSpacing + spacing;
                    }
                }
            }
            else
            {
                CalcDefaultSizes(size.Width, size.Height);
                double ys = 0;
                double ye = size.Height + spacing;
                for (int n = 0; n < visibleChildren.Length; n++)
                {
                    var bp = visibleChildren [n];
                    if (bp.PackOrigin == PackOrigin.End)
                    {
                        ye -= bp.NextSize + spacing;
                    }

                    double height = bp.NextSize >= 0 ? bp.NextSize : 0;
                    double width  = size.Width - bp.Child.Margin.HorizontalSpacing;
                    if (bp.Child.HorizontalPlacement != WidgetPlacement.Fill)
                    {
                        width = Math.Min(bp.Child.Surface.GetPreferredSize(SizeConstraint.Unconstrained, height).Width, width);
                    }
                    double x = (size.Width - bp.Child.Margin.HorizontalSpacing - width) * bp.Child.HorizontalPlacement.GetValue();
                    double y = bp.PackOrigin == PackOrigin.Start ? ys : ye;

                    widgets[n] = (IWidgetBackend)GetBackend(bp.Child);
                    rects[n]   = new Rectangle(x + bp.Child.MarginLeft, y + bp.Child.MarginTop, width, height).Round().WithPositiveSize();
                    if (bp.PackOrigin == PackOrigin.Start)
                    {
                        ys += bp.NextSize + bp.Child.Margin.VerticalSpacing + spacing;
                    }
                }
            }
            Backend.SetAllocation(widgets, rects);

            if (!BackendHost.EngineBackend.HandlesSizeNegotiation)
            {
                foreach (var bp in visibleChildren)
                {
                    bp.Child.Surface.Reallocate();
                }
            }
        }