1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-10-31 21:00:51 +01:00

added PreventParentSpill to Element

This commit is contained in:
Ellpeck 2020-06-12 02:04:01 +02:00
parent f2c544dc65
commit 601423407d
2 changed files with 18 additions and 2 deletions

View file

@ -253,6 +253,12 @@ namespace MLEM.Ui.Elements {
/// </summary>
public bool SetWidthBasedOnChildren;
/// <summary>
/// Set this field to true to cause this element's final display area to never exceed that of its <see cref="Parent"/>.
/// If the resulting area is too large, the size of this element is shrunk to fit the target area.
/// This can be useful if an element should fill the remaining area of a parent exactly.
/// </summary>
public bool PreventParentSpill;
/// <summary>
/// The transparency (alpha value) that this element is rendered with.
/// Note that, when <see cref="Draw"/> is called, this alpha value is multiplied with the <see cref="Parent"/>'s alpha value and passed down to this element's <see cref="Children"/>.
/// </summary>
@ -576,6 +582,17 @@ namespace MLEM.Ui.Elements {
}
}
if (this.PreventParentSpill) {
if (pos.X < parentArea.X)
pos.X = parentArea.X;
if (pos.Y < parentArea.Y)
pos.Y = parentArea.Y;
if (pos.X + actualSize.X > parentArea.Right)
actualSize.X = parentArea.Right - pos.X;
if (pos.Y + actualSize.Y > parentArea.Bottom)
actualSize.Y = parentArea.Bottom - pos.Y;
}
this.area = new RectangleF(pos, actualSize);
this.System.OnElementAreaUpdated?.Invoke(this);

View file

@ -149,8 +149,7 @@ namespace Sandbox {
var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero);
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(0.25F, -1)));
testPanel.AddChild(new Button(Anchor.AutoInline, new Vector2(0.25F, -1.5F)));
testPanel.AddChild(new Button(Anchor.AutoInline, new Vector2(0.5F, -1)));
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(2500, 1)) {PreventParentSpill = true});
this.UiSystem.Add("Test", testPanel);
}