private void PreTargetStarDefinitions(double size, DefinitionProxy[] proxies, double stars)
{
// Find the size that needs allocating to Star defs (by removing Auto/Fixed sizes from incoming total size)
int starDefs = 0;
foreach (DefinitionProxy proxy in proxies)
if (proxy.UserGridUnitType != GridUnitType.Star)
size -= proxy.MinSize;
else
starDefs++;
// Is there any size left to allocate to the Star defs?
if (size > 0)
{
// Handle defs where the allocated space is outside the min/max limits
foreach (DefinitionProxy proxy in proxies)
if (proxy.UserGridUnitType == GridUnitType.Star)
{
// Only interested if the definition has a defined min or max value
if ((proxy.DefUserMin > 0) || (proxy.DefUserMax < double.PositiveInfinity))
{
// How much size should this definition have based on its Star value
double allocateSize = size;
if (starDefs > 1)
allocateSize = size / stars * proxy.DefUserSize.Value;
// If allocated size is less than the defined minimum
if ((proxy.DefUserMin > 0) && (allocateSize < proxy.DefUserMin))
{
// Enfore minimum setting
proxy.StarAllocated = true;
proxy.MinSize = proxy.DefUserMin;
proxy.MeasureSize = proxy.DefUserMin;
stars -= proxy.DefUserSize.Value;
size -= proxy.MinSize;
starDefs--;
}
else if ((proxy.DefUserMax < double.PositiveInfinity) && (allocateSize > proxy.DefUserMax))
{
// Enfore maximum setting
proxy.StarAllocated = true;
proxy.MinSize = proxy.DefUserMax;
proxy.MeasureSize = proxy.DefUserMax;
stars -= proxy.DefUserSize.Value;
size -= proxy.MinSize;
starDefs--;
}
}
}
// Any more Star defs to allocate?
if ((starDefs > 0) && (size > 0))
{
// Allocate remaining space to remaining star defs according to Star values
foreach (DefinitionProxy proxy in proxies)
if ((proxy.UserGridUnitType == GridUnitType.Star) && !proxy.StarAllocated)
{
// How much size should this definition have based on its Star value
double allocateSize = size;
if (starDefs > 1)
allocateSize = size / stars * proxy.DefUserSize.Value;
proxy.StarAllocated = true;
proxy.MinSize = allocateSize;
proxy.MeasureSize = allocateSize;
stars -= proxy.DefUserSize.Value;
size -= proxy.MinSize;
starDefs--;
}
}
}
// Reset the star allocated field
foreach (DefinitionProxy proxy in proxies)
if (proxy.UserGridUnitType == GridUnitType.Star)
proxy.StarAllocated = false;
}