Exemplo n.º 1
0
        double GetAverageLineInfo(

            Size availableSize,
            VirtualizingLayoutContext context,
            FlowLayoutState flowState,
            double avgCountInLine)
        {
            // default to 1 item per line with 0 size
            double avgLineSize = 0;

            avgCountInLine = 1;

            MUX_ASSERT(context.ItemCount > 0);
            if (flowState.TotalLinesMeasured == 0)
            {
                var tmpElement  = context.GetOrCreateElementAt(0, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle);
                var desiredSize = flowState.FlowAlgorithm.MeasureElement(tmpElement, 0, availableSize, context);
                context.RecycleElement(tmpElement);

                int estimatedCountInLine = Math.Max(1, (int)(Minor(availableSize) / Minor(desiredSize)));
                flowState.OnLineArranged(0, estimatedCountInLine, Major(desiredSize), context);
                flowState.SpecialElementDesiredSize = desiredSize;
            }

            avgCountInLine = Math.Max(1.0, flowState.TotalItemsPerLine / flowState.TotalLinesMeasured);
            avgLineSize    = Math.Round(flowState.TotalLineSize / flowState.TotalLinesMeasured);

            return(_uno_lastKnownAverageLineSize = avgLineSize);
        }
Exemplo n.º 2
0
        protected internal override void InitializeForContextCore(VirtualizingLayoutContext context)
        {
            var             state     = context.LayoutState;
            FlowLayoutState flowState = default;

            if (state != null)
            {
                flowState = GetAsFlowState(state);
            }

            if (flowState == null)
            {
                if (state != null)
                {
                    throw new InvalidOperationException("LayoutState must derive from FlowLayoutState.");
                }

                // Custom deriving layouts could potentially be stateful.
                // If that is the case, we will just create the base state required by FlowLayout ourselves.
                flowState = new FlowLayoutState();
            }

            flowState.InitializeForContext(context, this);
        }