// -----------------------------------------------------------------------
//
// Copyright 2015 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Layout
{
using System;
///
/// Provides helper methods needed for layout.
///
public static class LayoutHelper
{
///
/// Calculates a control's size based on its ,
/// , ,
/// , and
/// .
///
/// The control.
/// The space available for the control.
/// The control's size.
public static Size ApplyLayoutConstraints(ILayoutable control, Size constraints)
{
double width = (control.Width > 0) ? control.Width : constraints.Width;
double height = (control.Height > 0) ? control.Height : constraints.Height;
width = Math.Min(width, control.MaxWidth);
width = Math.Max(width, control.MinWidth);
height = Math.Min(height, control.MaxHeight);
height = Math.Max(height, control.MinHeight);
return new Size(width, height);
}
}
}