public static void Autoresize(double oldContainerSize,
double newContainerSize,
ref double contentPositionInOut,
ref double contentSizeInOut,
bool minMarginFlexible,
bool sizeFlexible,
bool maxMarginFlexible)
{
double change = newContainerSize - oldContainerSize;
double oldContentSize = contentSizeInOut;
double oldContentPosition = contentPositionInOut;
double flexibleSpace = 0.0;
// See how much flexible space we have to distrube the change over
if (sizeFlexible)
flexibleSpace += oldContentSize;
if (minMarginFlexible)
flexibleSpace += oldContentPosition;
if (maxMarginFlexible)
flexibleSpace += oldContainerSize - oldContentPosition - oldContentSize;
if (flexibleSpace <= 0.0)
{
/**
* In this code path there is no flexible space so we divide
* the available space equally among the flexible portions of the view
*/
int subdivisions = (sizeFlexible ? 1 : 0) +
(minMarginFlexible ? 1 : 0) +
(maxMarginFlexible ? 1 : 0);
if (subdivisions > 0)
{
double changePerOption = change / subdivisions;
if (sizeFlexible)
{
contentSizeInOut += changePerOption;
}
if (minMarginFlexible)
{
contentPositionInOut += changePerOption;
}
}
}
else
{
/**
* In this code path we distribute the change proportionately
* over the flexible spaces
*/
double changePerPoint = change / flexibleSpace;
if (sizeFlexible)
{
contentSizeInOut += changePerPoint * oldContentSize;
}
if (minMarginFlexible)
{
contentPositionInOut += changePerPoint * oldContentPosition;
}
}
}