mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Improved the SquishingGroup algorithm by prioritizing each element's final size
This commit is contained in:
parent
1a7cb65cf2
commit
2265af3fae
3 changed files with 36 additions and 45 deletions
17
CHANGELOG.md
17
CHANGELOG.md
|
@ -18,17 +18,17 @@ Additions
|
||||||
- Added the ability to add inverse modifiers to a Keybind
|
- Added the ability to add inverse modifiers to a Keybind
|
||||||
- Added GenericInput collections AllKeys, AllMouseButtons, AllButtons and AllInputs
|
- Added GenericInput collections AllKeys, AllMouseButtons, AllButtons and AllInputs
|
||||||
|
|
||||||
|
Improvements
|
||||||
|
- Increased TextFormatter macro recursion limit to 64
|
||||||
|
- Allow changing the default values used by default TextFormatter codes
|
||||||
|
- Allow setting ExternalGestureHandling through the InputHandler constructor
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed control characters being included in TextInput
|
- Fixed control characters being included in TextInput
|
||||||
- Fixed TextInputs behaving incorrectly when switching between multiline and single-line modes
|
- Fixed TextInputs behaving incorrectly when switching between multiline and single-line modes
|
||||||
- Fixed TextInput drawing characters with the wrong width if a masking character is used
|
- Fixed TextInput drawing characters with the wrong width if a masking character is used
|
||||||
- Fixed a multiline TextInput's cursor not returning to the default position when the last character is removed
|
- Fixed a multiline TextInput's cursor not returning to the default position when the last character is removed
|
||||||
|
|
||||||
Improvements
|
|
||||||
- Increased TextFormatter macro recursion limit to 64
|
|
||||||
- Allow changing the default values used by default TextFormatter codes
|
|
||||||
- Allow setting ExternalGestureHandling through the InputHandler constructor
|
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
- Marked GetDownTime, GetUpTime and GetTimeSincePress in Keybind and Combination as obsolete
|
- Marked GetDownTime, GetUpTime and GetTimeSincePress in Keybind and Combination as obsolete
|
||||||
|
|
||||||
|
@ -36,14 +36,15 @@ Removals
|
||||||
Additions
|
Additions
|
||||||
- Added AutoInlineCenter and AutoInlineBottom anchors
|
- Added AutoInlineCenter and AutoInlineBottom anchors
|
||||||
|
|
||||||
|
Improvements
|
||||||
|
- Increased Element area calculation recursion limit to 64
|
||||||
|
- Improved the SquishingGroup algorithm by prioritizing each element's final size
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed images not updating their hidden state properly when the displayed texture changes
|
- Fixed images not updating their hidden state properly when the displayed texture changes
|
||||||
- Fixed AutoInline elements overflowing into their parent if it's taller
|
- Fixed AutoInline elements overflowing into their parent if it's taller
|
||||||
- Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly
|
- Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly
|
||||||
|
|
||||||
Improvements
|
|
||||||
- Increased Element area calculation recursion limit to 64
|
|
||||||
|
|
||||||
## 6.1.0
|
## 6.1.0
|
||||||
|
|
||||||
### MLEM
|
### MLEM
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Extensions;
|
using MLEM.Extensions;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
|
||||||
namespace MLEM.Ui.Elements {
|
namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A squishing group is a <see cref="Group"/> whose <see cref="Element.Children"/> automatically get resized so that they do not overlap each other.
|
/// A squishing group is a <see cref="Group"/> whose <see cref="Element.Children"/> automatically get resized so that they do not overlap each other. Elements are squished in a way that maximizes the final area that each element retains compared to its original area.
|
||||||
/// The order in which elements are squished depends on their <see cref="Element.Priority"/>, where elements with a lower priority will move out of the way of elements with a higher priority.
|
/// The order in which elements are squished depends on their <see cref="Element.Priority"/>, where elements with a lower priority will move out of the way of elements with a higher priority. If all elements have the same priority, their addition order (their order in <see cref="Element.Children"/>) determines squish order.
|
||||||
/// If all elements have the same priority, their addition order (their order in <see cref="Element.Children"/>) determines squish order.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SquishingGroup : Group {
|
public class SquishingGroup : Group {
|
||||||
|
|
||||||
|
@ -43,27 +43,17 @@ namespace MLEM.Ui.Elements {
|
||||||
var pos = element.Area.Location;
|
var pos = element.Area.Location;
|
||||||
var size = element.Area.Size;
|
var size = element.Area.Size;
|
||||||
foreach (var sibling in element.GetSiblings(e => !e.IsHidden)) {
|
foreach (var sibling in element.GetSiblings(e => !e.IsHidden)) {
|
||||||
var siblingArea = sibling.Area;
|
var sibArea = sibling.Area;
|
||||||
var leftIntersect = siblingArea.Right - pos.X;
|
if (pos.X < sibArea.Right && sibArea.Left < pos.X + size.X && pos.Y < sibArea.Bottom && sibArea.Top < pos.Y + size.Y) {
|
||||||
var rightIntersect = pos.X + size.X - siblingArea.Left;
|
var possible = new[] {
|
||||||
var bottomIntersect = siblingArea.Bottom - pos.Y;
|
new RectangleF(Math.Max(pos.X, sibArea.Right), pos.Y, size.X - (sibArea.Right - pos.X), size.Y),
|
||||||
var topIntersect = pos.Y + size.Y - siblingArea.Top;
|
new RectangleF(pos.X, pos.Y, Math.Min(pos.X + size.X, sibArea.Left) - pos.X, size.Y),
|
||||||
if (leftIntersect > 0 && rightIntersect > 0 && bottomIntersect > 0 && topIntersect > 0) {
|
new RectangleF(pos.X, Math.Max(pos.Y, sibArea.Bottom), size.X, size.Y - (sibArea.Bottom - pos.Y)),
|
||||||
if (rightIntersect + leftIntersect < topIntersect + bottomIntersect) {
|
new RectangleF(pos.X, pos.Y, size.X, Math.Min(pos.Y + size.Y, sibArea.Top) - pos.Y)
|
||||||
if (rightIntersect > leftIntersect) {
|
};
|
||||||
size.X -= siblingArea.Right - pos.X;
|
var biggest = possible.OrderByDescending(r => r.Width * r.Height).First();
|
||||||
pos.X = Math.Max(pos.X, siblingArea.Right);
|
pos = biggest.Location;
|
||||||
} else {
|
size = biggest.Size;
|
||||||
size.X = Math.Min(pos.X + size.X, siblingArea.Left) - pos.X;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (topIntersect > bottomIntersect) {
|
|
||||||
size.Y -= siblingArea.Bottom - pos.Y;
|
|
||||||
pos.Y = Math.Max(pos.Y, siblingArea.Bottom);
|
|
||||||
} else {
|
|
||||||
size.Y = Math.Min(pos.Y + size.Y, siblingArea.Top) - pos.Y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pos.Equals(element.Area.Location, Element.Epsilon) || !size.Equals(element.Area.Size, Element.Epsilon)) {
|
if (!pos.Equals(element.Area.Location, Element.Epsilon) || !size.Equals(element.Area.Size, Element.Epsilon)) {
|
||||||
|
|
|
@ -229,22 +229,22 @@ public class GameImpl : MlemGame {
|
||||||
par.OnDrawn = (e, time, batch, a) => batch.DrawRectangle(e.DisplayArea.ToExtended(), Color.Red);
|
par.OnDrawn = (e, time, batch, a) => batch.DrawRectangle(e.DisplayArea.ToExtended(), Color.Red);
|
||||||
this.UiSystem.Add("Load", loadGroup);*/
|
this.UiSystem.Add("Load", loadGroup);*/
|
||||||
|
|
||||||
/*var spillPanel = new Panel(Anchor.Center, new Vector2(100), Vector2.Zero);
|
var spillPanel = new Panel(Anchor.Center, new Vector2(100), Vector2.Zero);
|
||||||
var squishingGroup = spillPanel.AddChild(new SquishingGroup(Anchor.TopLeft, Vector2.One));
|
var squishingGroup = spillPanel.AddChild(new SquishingGroup(Anchor.TopLeft, Vector2.One));
|
||||||
squishingGroup.AddChild(new Button(Anchor.TopLeft, new Vector2(30), "TL") {
|
squishingGroup.AddChild(new Button(Anchor.TopLeft, new Vector2(30), "TL") {
|
||||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D1),
|
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D1),
|
||||||
Priority = 10
|
Priority = 10
|
||||||
}).SetData("Ref", "TL");
|
}).SetData("Ref", "TL");
|
||||||
squishingGroup.AddChild(new Button(Anchor.TopRight, new Vector2(30), "TR") {
|
squishingGroup.AddChild(new Button(Anchor.TopRight, new Vector2(30), "TR") {
|
||||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D2),
|
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D2),
|
||||||
Priority = 20
|
Priority = 20
|
||||||
}).SetData("Ref", "TR");
|
}).SetData("Ref", "TR");
|
||||||
squishingGroup.AddChild(new Button(Anchor.BottomLeft, new Vector2(30), "BL") {
|
squishingGroup.AddChild(new Button(Anchor.BottomLeft, new Vector2(1, 30), "BL") {
|
||||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D3),
|
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D3),
|
||||||
Priority = 30
|
Priority = 30
|
||||||
}).SetData("Ref", "BL");
|
}).SetData("Ref", "BL");
|
||||||
squishingGroup.AddChild(new Button(Anchor.BottomRight, new Vector2(30), "BR") {
|
squishingGroup.AddChild(new Button(Anchor.BottomRight, new Vector2(30), "BR") {
|
||||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D4),
|
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D4),
|
||||||
Priority = 40
|
Priority = 40
|
||||||
}).SetData("Ref", "BR");
|
}).SetData("Ref", "BR");
|
||||||
squishingGroup.AddChild(new Button(Anchor.Center, Vector2.Zero, "0") {
|
squishingGroup.AddChild(new Button(Anchor.Center, Vector2.Zero, "0") {
|
||||||
|
@ -256,7 +256,7 @@ public class GameImpl : MlemGame {
|
||||||
e.SetAreaDirty();
|
e.SetAreaDirty();
|
||||||
}
|
}
|
||||||
}).SetData("Ref", "Main");
|
}).SetData("Ref", "Main");
|
||||||
this.UiSystem.Add("SpillTest", spillPanel);*/
|
this.UiSystem.Add("SpillTest", spillPanel);
|
||||||
|
|
||||||
/* var regularFont = spriteFont.Font;
|
/* var regularFont = spriteFont.Font;
|
||||||
var genericFont = spriteFont;
|
var genericFont = spriteFont;
|
||||||
|
@ -343,7 +343,7 @@ public class GameImpl : MlemGame {
|
||||||
this.SpriteBatch.End();
|
this.SpriteBatch.End();
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
var widthPanel = new Panel(Anchor.Center, Vector2.One, Vector2.Zero, true) {SetWidthBasedOnChildren = true};
|
/*var widthPanel = new Panel(Anchor.Center, Vector2.One, Vector2.Zero, true) {SetWidthBasedOnChildren = true};
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
||||||
OnUpdated = (e, _) => {
|
OnUpdated = (e, _) => {
|
||||||
|
@ -383,12 +383,12 @@ public class GameImpl : MlemGame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.OnDraw += (_, _) => batch.Draw(null, SamplerState.PointClamp, null, null, null, Matrix.CreateScale(3));
|
this.OnDraw += (_, _) => batch.Draw(null, SamplerState.PointClamp, null, null, null, Matrix.CreateScale(3));*/
|
||||||
|
|
||||||
Console.WriteLine("Keys: " + string.Join(", ", GenericInput.AllKeys));
|
/*Console.WriteLine("Keys: " + string.Join(", ", GenericInput.AllKeys));
|
||||||
Console.WriteLine("MouseButtons: " + string.Join(", ", GenericInput.AllMouseButtons));
|
Console.WriteLine("MouseButtons: " + string.Join(", ", GenericInput.AllMouseButtons));
|
||||||
Console.WriteLine("Buttons: " + string.Join(", ", GenericInput.AllButtons));
|
Console.WriteLine("Buttons: " + string.Join(", ", GenericInput.AllButtons));
|
||||||
Console.WriteLine("Inputs: " + string.Join(", ", GenericInput.AllInputs));
|
Console.WriteLine("Inputs: " + string.Join(", ", GenericInput.AllInputs));*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DoUpdate(GameTime gameTime) {
|
protected override void DoUpdate(GameTime gameTime) {
|
||||||
|
@ -410,8 +410,8 @@ public class GameImpl : MlemGame {
|
||||||
Console.WriteLine("Time since press: " + MlemGame.Input.GetTimeSincePress(Keys.A));#1#
|
Console.WriteLine("Time since press: " + MlemGame.Input.GetTimeSincePress(Keys.A));#1#
|
||||||
Console.WriteLine("Up time: " + MlemGame.Input.GetUpTime(Keys.A));*/
|
Console.WriteLine("Up time: " + MlemGame.Input.GetUpTime(Keys.A));*/
|
||||||
|
|
||||||
var combination = new Keybind.Combination(Keys.K, new GenericInput[] {Keys.LeftShift}, GenericInput.AllKeys);
|
/*var combination = new Keybind.Combination(Keys.K, new GenericInput[] {Keys.LeftShift}, GenericInput.AllKeys);
|
||||||
Console.WriteLine($"Mod: {combination.IsModifierDown(this.InputHandler)} Down: {combination.IsDown(this.InputHandler)}");
|
Console.WriteLine($"Mod: {combination.IsModifierDown(this.InputHandler)} Down: {combination.IsDown(this.InputHandler)}");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DoDraw(GameTime gameTime) {
|
protected override void DoDraw(GameTime gameTime) {
|
||||||
|
|
Loading…
Reference in a new issue