mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
added min/max width/height to gui controls
This commit is contained in:
@@ -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() { }
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user