mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-29 23:58:34 +01:00
Compare commits
No commits in common. "2265af3faeb86a18ab5e0ea4e0e913b75f8b9b2f" and "6607a5f48caa92e3c6edfc04f1e7cc56f49fb52a" have entirely different histories.
2265af3fae
...
6607a5f48c
9 changed files with 71 additions and 72 deletions
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -18,17 +18,17 @@ Additions
|
|||
- Added the ability to add inverse modifiers to a Keybind
|
||||
- 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
|
||||
- Fixed control characters being included in TextInput
|
||||
- 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 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
|
||||
- Marked GetDownTime, GetUpTime and GetTimeSincePress in Keybind and Combination as obsolete
|
||||
|
||||
|
@ -36,14 +36,12 @@ Removals
|
|||
Additions
|
||||
- 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
|
||||
- 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 Paragraph and Checkbox not reacting to SquishingGroup sizing properly
|
||||
|
||||
Improvements
|
||||
- Increased Element area calculation recursion limit to 64
|
||||
|
||||
## 6.1.0
|
||||
|
||||
|
|
|
@ -3,31 +3,31 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
|
|
|
@ -3,31 +3,31 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
|
|
|
@ -3,31 +3,31 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
|
|
|
@ -106,12 +106,13 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetAreaAndUpdateChildren(RectangleF area) {
|
||||
base.SetAreaAndUpdateChildren(area);
|
||||
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
||||
var size = base.CalcActualSize(parentArea);
|
||||
if (this.Label != null) {
|
||||
this.Label.Size = new Vector2((area.Width - area.Height) / this.Scale - this.TextOffsetX, 1);
|
||||
this.Label.PositionOffset = new Vector2(area.Height / this.Scale + this.TextOffsetX, 0);
|
||||
this.Label.Size = new Vector2((size.X - size.Y) / this.Scale - this.TextOffsetX, 1);
|
||||
this.Label.PositionOffset = new Vector2(size.Y / this.Scale + this.TextOffsetX, 0);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -175,13 +175,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.CanBeMoused = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetAreaAndUpdateChildren(RectangleF area) {
|
||||
base.SetAreaAndUpdateChildren(area);
|
||||
// in case an outside source sets our area, we still want to display our text correctly
|
||||
this.AlignAndSplitIfNecessary(area.Size);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
||||
var size = base.CalcActualSize(parentArea);
|
||||
|
@ -189,9 +182,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.TokenizeIfNecessary();
|
||||
this.AlignAndSplitIfNecessary(size);
|
||||
var textSize = this.tokenizedText.GetArea(Vector2.Zero, this.TextScale * this.TextScaleMultiplier * this.Scale).Size;
|
||||
// if we auto-adjust our width, then we would also split the same way with our adjusted width, so cache that
|
||||
if (this.AutoAdjustWidth)
|
||||
this.lastAlignSplitWidth = textSize.X;
|
||||
return new Vector2(this.AutoAdjustWidth ? textSize.X + this.ScaledPadding.Width : size.X, textSize.Y + this.ScaledPadding.Height);
|
||||
}
|
||||
|
||||
|
@ -265,7 +255,7 @@ namespace MLEM.Ui.Elements {
|
|||
var width = size.X - this.ScaledPadding.Width;
|
||||
var scale = this.TextScale * this.TextScaleMultiplier * this.Scale;
|
||||
|
||||
if (this.lastAlignSplitWidth?.Equals(width, Element.Epsilon) == true && this.lastAlignSplitScale?.Equals(scale, Element.Epsilon) == true)
|
||||
if (this.lastAlignSplitWidth == width && this.lastAlignSplitScale == scale)
|
||||
return;
|
||||
this.lastAlignSplitWidth = width;
|
||||
this.lastAlignSplitScale = scale;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Extensions;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Ui.Elements {
|
||||
/// <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. 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. If all elements have the same priority, their addition order (their order in <see cref="Element.Children"/>) determines squish order.
|
||||
/// A squishing group is a <see cref="Group"/> whose <see cref="Element.Children"/> automatically get resized so that they do not overlap each other.
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class SquishingGroup : Group {
|
||||
|
||||
|
@ -43,17 +43,27 @@ namespace MLEM.Ui.Elements {
|
|||
var pos = element.Area.Location;
|
||||
var size = element.Area.Size;
|
||||
foreach (var sibling in element.GetSiblings(e => !e.IsHidden)) {
|
||||
var sibArea = sibling.Area;
|
||||
if (pos.X < sibArea.Right && sibArea.Left < pos.X + size.X && pos.Y < sibArea.Bottom && sibArea.Top < pos.Y + size.Y) {
|
||||
var possible = new[] {
|
||||
new RectangleF(Math.Max(pos.X, sibArea.Right), pos.Y, size.X - (sibArea.Right - pos.X), size.Y),
|
||||
new RectangleF(pos.X, pos.Y, Math.Min(pos.X + size.X, sibArea.Left) - pos.X, size.Y),
|
||||
new RectangleF(pos.X, Math.Max(pos.Y, sibArea.Bottom), size.X, size.Y - (sibArea.Bottom - pos.Y)),
|
||||
new RectangleF(pos.X, pos.Y, size.X, Math.Min(pos.Y + size.Y, sibArea.Top) - pos.Y)
|
||||
};
|
||||
var biggest = possible.OrderByDescending(r => r.Width * r.Height).First();
|
||||
pos = biggest.Location;
|
||||
size = biggest.Size;
|
||||
var siblingArea = sibling.Area;
|
||||
var leftIntersect = siblingArea.Right - pos.X;
|
||||
var rightIntersect = pos.X + size.X - siblingArea.Left;
|
||||
var bottomIntersect = siblingArea.Bottom - pos.Y;
|
||||
var topIntersect = pos.Y + size.Y - siblingArea.Top;
|
||||
if (leftIntersect > 0 && rightIntersect > 0 && bottomIntersect > 0 && topIntersect > 0) {
|
||||
if (rightIntersect + leftIntersect < topIntersect + bottomIntersect) {
|
||||
if (rightIntersect > leftIntersect) {
|
||||
size.X -= siblingArea.Right - pos.X;
|
||||
pos.X = Math.Max(pos.X, siblingArea.Right);
|
||||
} else {
|
||||
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)) {
|
||||
|
|
|
@ -3,31 +3,31 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.1.303",
|
||||
"version": "3.8.1.263",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
|
|
|
@ -229,22 +229,22 @@ public class GameImpl : MlemGame {
|
|||
par.OnDrawn = (e, time, batch, a) => batch.DrawRectangle(e.DisplayArea.ToExtended(), Color.Red);
|
||||
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));
|
||||
squishingGroup.AddChild(new Button(Anchor.TopLeft, new Vector2(30), "TL") {
|
||||
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D1),
|
||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D1),
|
||||
Priority = 10
|
||||
}).SetData("Ref", "TL");
|
||||
squishingGroup.AddChild(new Button(Anchor.TopRight, new Vector2(30), "TR") {
|
||||
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D2),
|
||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D2),
|
||||
Priority = 20
|
||||
}).SetData("Ref", "TR");
|
||||
squishingGroup.AddChild(new Button(Anchor.BottomLeft, new Vector2(1, 30), "BL") {
|
||||
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D3),
|
||||
squishingGroup.AddChild(new Button(Anchor.BottomLeft, new Vector2(30), "BL") {
|
||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D3),
|
||||
Priority = 30
|
||||
}).SetData("Ref", "BL");
|
||||
squishingGroup.AddChild(new Button(Anchor.BottomRight, new Vector2(30), "BR") {
|
||||
OnUpdated = (e, time) => e.IsHidden = MlemGame.Input.IsDown(Keys.D4),
|
||||
OnUpdated = (e, time) => e.IsHidden = Input.IsKeyDown(Keys.D4),
|
||||
Priority = 40
|
||||
}).SetData("Ref", "BR");
|
||||
squishingGroup.AddChild(new Button(Anchor.Center, Vector2.Zero, "0") {
|
||||
|
@ -256,7 +256,7 @@ public class GameImpl : MlemGame {
|
|||
e.SetAreaDirty();
|
||||
}
|
||||
}).SetData("Ref", "Main");
|
||||
this.UiSystem.Add("SpillTest", spillPanel);
|
||||
this.UiSystem.Add("SpillTest", spillPanel);*/
|
||||
|
||||
/* var regularFont = spriteFont.Font;
|
||||
var genericFont = spriteFont;
|
||||
|
@ -343,7 +343,7 @@ public class GameImpl : MlemGame {
|
|||
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++) {
|
||||
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
||||
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("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) {
|
||||
|
@ -410,8 +410,8 @@ public class GameImpl : MlemGame {
|
|||
Console.WriteLine("Time since press: " + MlemGame.Input.GetTimeSincePress(Keys.A));#1#
|
||||
Console.WriteLine("Up time: " + MlemGame.Input.GetUpTime(Keys.A));*/
|
||||
|
||||
/*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)}");*/
|
||||
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)}");
|
||||
}
|
||||
|
||||
protected override void DoDraw(GameTime gameTime) {
|
||||
|
|
Loading…
Reference in a new issue