예제 #1
0
        ValueSize IVisualRenderer.Measure <TRenderSize>(TRenderSize availableSpace,
                                                        IMeasureContext measureContext)
        {
            if (Content is {} content)
            {
                return(measureContext.MeasureElement(content, availableSpace));
            }

            return(ValueSize.Empty);
        }
예제 #2
0
        public override ValueSize Measure <TRenderSize>(TRenderSize availableSpace,
                                                        IMeasureContext measureContext)
        {
            if (Children.Count == 0)
            {
                return(ValueSize.Empty);
            }

            var useWidth  = 0.0;
            var useHeight = 0.0;

            foreach (var child in Children.GetAllChildren())
            {
                var childMeasures = measureContext.MeasureElement(child, availableSpace);

                useWidth  = Math.Max(useWidth, childMeasures.Width);
                useHeight = Math.Max(useHeight, childMeasures.Height);
            }

            return(new ValueSize(useWidth, useHeight));
        }
예제 #3
0
        protected ValueThickness MeasureImpl <TRenderSize>(IVisualElement container,
                                                           IMeasureContext measureContext,
                                                           TRenderSize availableSpace,
                                                           Orientations orientation,
                                                           List <IVisualElement> currentlyRendering,
                                                           out Double maxWidth,
                                                           out Double maxHeight,
                                                           out Double totalWidth,
                                                           out Double totalHeight)
            where TRenderSize : IRenderSize
        {
            var remainingSize = new RenderSize(availableSpace.Width,
                                               availableSpace.Height, availableSpace.Offset);
            var current = new RenderRectangle();

            totalHeight = 0.0;
            totalWidth  = 0.0;

            maxWidth  = 0.0;
            maxHeight = 0.0;

            foreach (var child in _visuals.GetAllChildren())
            {
                currentlyRendering.Add(child);


                current.Size = measureContext.MeasureElement(child, remainingSize);
                var offset = SetChildSize(child, current);
                if (!offset.IsEmpty)
                {
                    current.Width  += offset.Width;
                    current.Height += offset.Height;
                }

                switch (orientation)
                {
                case Orientations.Horizontal:
                    if (current.Height > maxHeight)
                    {
                        maxHeight = current.Height;
                    }

                    if (_isWrapContent && current.Width + totalWidth > availableSpace.Width &&
                        totalHeight + maxHeight < availableSpace.Height)
                    {
                        maxWidth     = Math.Max(maxWidth, totalWidth);
                        totalHeight += maxHeight;

                        current.X  = 0;
                        current.Y += maxHeight;
                        maxHeight  = totalWidth = 0;
                    }

                    current.X           += current.Width;
                    totalWidth          += current.Width;
                    remainingSize.Width -= current.Width;
                    break;

                case Orientations.Vertical:
                    if (current.Width > totalWidth)
                    {
                        totalWidth = current.Width;
                    }

                    if (_isWrapContent && current.Height + totalHeight > availableSpace.Height &&
                        totalWidth + maxWidth < availableSpace.Width)
                    {
                        maxHeight   = Math.Max(maxHeight, totalHeight);
                        totalWidth += maxWidth;

                        current.Y  = 0;
                        current.X += maxHeight;
                        maxWidth   = totalHeight = 0;
                    }

                    current.Y            += current.Height;
                    totalHeight          += current.Height;
                    remainingSize.Height -= current.Height;
                    break;
                }
            }

            var margin = container.Margin.GetValue(availableSpace);

            return(margin);
        }