added min/max width/height to gui controls

This commit is contained in:
Dylan Wilson
2018-03-23 22:37:01 +10:00
parent 8962541d36
commit 7d42751468
2 changed files with 21 additions and 1 deletions
@@ -105,7 +105,22 @@ namespace MonoGame.Extended.Gui.Controls
{
var fixedSize = Size;
var desiredSize = GetContentSize(context) + Margin.Size + Padding.Size;
return new Size(fixedSize.Width == 0 ? desiredSize.Width : fixedSize.Width, fixedSize.Height == 0 ? desiredSize.Height : fixedSize.Height);
if (desiredSize.Width < MinWidth)
desiredSize.Width = MinWidth;
if (desiredSize.Height < MinHeight)
desiredSize.Height = MinHeight;
if (desiredSize.Width > MaxWidth)
desiredSize.Width = MaxWidth;
if (desiredSize.Height > MaxWidth)
desiredSize.Height = MaxHeight;
var width = fixedSize.Width == 0 ? desiredSize.Width : fixedSize.Width;
var height = fixedSize.Height == 0 ? desiredSize.Height : fixedSize.Height;
return new Size(width, height);
}
public virtual void InvalidateMeasure() { }
+5
View File
@@ -78,6 +78,11 @@ namespace MonoGame.Extended.Gui
protected virtual void OnSizeChanged() { }
public int MinWidth { get; set; }
public int MinHeight { get; set; }
public int MaxWidth { get; set; } = int.MaxValue;
public int MaxHeight { get; set; } = int.MaxValue;
public int Width
{
get { return Size.Width; }