Ejemplo n.º 1
0
        private ResizeGroupState <TObject> UpdateContainerDimension(double oldDimension, double newDimension, TObject fullDimensionData, TObject renderedData)
        {
            ResizeGroupState <TObject> nextState;

            if (double.IsNaN(oldDimension))
            {
                throw new Exception("The containerDimension was not supposed to be NaN");
            }
            if (newDimension > oldDimension)
            {
                if (OnGrowData != null)
                {
                    nextState = new ResizeGroupState <TObject>(ResizeDirection.Grow, OnGrowData(renderedData));
                }
                else
                {
                    nextState = new ResizeGroupState <TObject>(ResizeDirection.Shrink, fullDimensionData);
                }
            }
            else
            {
                nextState = new ResizeGroupState <TObject>(ResizeDirection.Shrink, renderedData);
            }

            nextState.ContainerDimension = newDimension;
            nextState.MeasureContainer   = false;
            return(nextState);
        }
Ejemplo n.º 2
0
        public void ReplaceProperties(ResizeGroupState <TObject> nextState)
        {
            if (nextState.RenderedData != null)
            {
                RenderedData = nextState.RenderedData;
            }
            if (nextState.DataToMeasure != null)
            {
                DataToMeasure = nextState.DataToMeasure;
            }
            if (nextState.ResizeDirection != ResizeDirection.None)
            {
                ResizeDirection = nextState.ResizeDirection;
            }
            if (nextState.ContainerDimension != 0)
            {
                ContainerDimension = nextState.ContainerDimension;
            }

            MeasureContainer = nextState.MeasureContainer;

            if (nextState.NullifyDataToMeasure)
            {
                DataToMeasure = default;
            }
            if (nextState.NullifyRenderedData)
            {
                RenderedData = default;
            }
            if (nextState.ForceNoneResizeDirection)
            {
                ResizeDirection = ResizeDirection.None;
            }
        }
Ejemplo n.º 3
0
        private async Task <ResizeGroupState <TObject> > GetNextStateAsync(double newContainerDimension, double oldContainerDimension, TObject dataToMeasure, TObject renderedData, ResizeDirection resizeDirection, CancellationToken cancellationToken)
        {
            double replacementContainerDimension = oldContainerDimension;

            if (double.IsNaN(newContainerDimension) && dataToMeasure == null)
            {
                return(null);
            }

            if (!double.IsNaN(newContainerDimension))
            {
                // If we know what the last container size was and we rendered data at that width/height, we can do an optimized render
                if (!double.IsNaN(oldContainerDimension) && renderedData != null && dataToMeasure == null)
                {
                    var state        = new ResizeGroupState <TObject>(renderedData, resizeDirection, dataToMeasure);
                    var alteredState = UpdateContainerDimension(oldContainerDimension, newContainerDimension, this.Data, renderedData);
                    state.ReplaceProperties(alteredState);
                    return(state);
                }

                replacementContainerDimension = newContainerDimension;
            }

            var nextState = new ResizeGroupState <TObject>(renderedData, resizeDirection, dataToMeasure);

            nextState.MeasureContainer = false;
            if (replacementContainerDimension != oldContainerDimension)
            {
                nextState.ContainerDimension = replacementContainerDimension;
            }

            if (dataToMeasure != null)
            {
                //get elementDimension here
                var elementDimension = await GetElementDimensionsAsync(cancellationToken);

                if (resizeDirection == ResizeDirection.Grow && this.OnGrowData != null)
                {
                    var alteredState = GrowDataUntilItDoesNotFit(dataToMeasure, elementDimension, replacementContainerDimension);
                    nextState.ReplaceProperties(alteredState);
                }
                else
                {
                    var alteredState = ShrinkContentsUntilTheyFit(dataToMeasure, elementDimension, replacementContainerDimension);
                    nextState.ReplaceProperties(alteredState);
                }
            }


            return(nextState);
        }