csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.5 KiB
36 lines
1.5 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="LayoutHelper.cs" company="Steven Kirk">
|
|
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Layout
|
|
{
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// Provides helper methods needed for layout.
|
|
/// </summary>
|
|
public static class LayoutHelper
|
|
{
|
|
/// <summary>
|
|
/// Calculates a control's size based on its <see cref="ILayoutable.Width"/>,
|
|
/// <see cref="ILayoutable.Height"/>, <see cref="ILayoutable.MinWidth"/>,
|
|
/// <see cref="ILayoutable.MaxWidth"/>, <see cref="ILayoutable.MinHeight"/> and
|
|
/// <see cref="ILayoutable.MaxHeight"/>.
|
|
/// </summary>
|
|
/// <param name="control">The control.</param>
|
|
/// <param name="constraints">The space available for the control.</param>
|
|
/// <returns>The control's size.</returns>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|