1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38:34 +01:00

Compare commits

...

3 commits

9 changed files with 72 additions and 71 deletions

View file

@ -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,12 +36,14 @@ 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
Improvements
- Increased Element area calculation recursion limit to 64
## 6.1.0 ## 6.1.0

View file

@ -3,31 +3,31 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"dotnet-mgcb": { "dotnet-mgcb": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb" "mgcb"
] ]
}, },
"dotnet-mgcb-editor": { "dotnet-mgcb-editor": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor" "mgcb-editor"
] ]
}, },
"dotnet-mgcb-editor-linux": { "dotnet-mgcb-editor-linux": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-linux" "mgcb-editor-linux"
] ]
}, },
"dotnet-mgcb-editor-windows": { "dotnet-mgcb-editor-windows": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-windows" "mgcb-editor-windows"
] ]
}, },
"dotnet-mgcb-editor-mac": { "dotnet-mgcb-editor-mac": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-mac" "mgcb-editor-mac"
] ]

View file

@ -3,31 +3,31 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"dotnet-mgcb": { "dotnet-mgcb": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb" "mgcb"
] ]
}, },
"dotnet-mgcb-editor": { "dotnet-mgcb-editor": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor" "mgcb-editor"
] ]
}, },
"dotnet-mgcb-editor-linux": { "dotnet-mgcb-editor-linux": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-linux" "mgcb-editor-linux"
] ]
}, },
"dotnet-mgcb-editor-windows": { "dotnet-mgcb-editor-windows": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-windows" "mgcb-editor-windows"
] ]
}, },
"dotnet-mgcb-editor-mac": { "dotnet-mgcb-editor-mac": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-mac" "mgcb-editor-mac"
] ]

View file

@ -3,31 +3,31 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"dotnet-mgcb": { "dotnet-mgcb": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb" "mgcb"
] ]
}, },
"dotnet-mgcb-editor": { "dotnet-mgcb-editor": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor" "mgcb-editor"
] ]
}, },
"dotnet-mgcb-editor-linux": { "dotnet-mgcb-editor-linux": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-linux" "mgcb-editor-linux"
] ]
}, },
"dotnet-mgcb-editor-windows": { "dotnet-mgcb-editor-windows": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-windows" "mgcb-editor-windows"
] ]
}, },
"dotnet-mgcb-editor-mac": { "dotnet-mgcb-editor-mac": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-mac" "mgcb-editor-mac"
] ]

View file

@ -106,13 +106,12 @@ namespace MLEM.Ui.Elements {
} }
/// <inheritdoc /> /// <inheritdoc />
protected override Vector2 CalcActualSize(RectangleF parentArea) { public override void SetAreaAndUpdateChildren(RectangleF area) {
var size = base.CalcActualSize(parentArea); base.SetAreaAndUpdateChildren(area);
if (this.Label != null) { if (this.Label != null) {
this.Label.Size = new Vector2((size.X - size.Y) / this.Scale - this.TextOffsetX, 1); this.Label.Size = new Vector2((area.Width - area.Height) / this.Scale - this.TextOffsetX, 1);
this.Label.PositionOffset = new Vector2(size.Y / this.Scale + this.TextOffsetX, 0); this.Label.PositionOffset = new Vector2(area.Height / this.Scale + this.TextOffsetX, 0);
} }
return size;
} }
/// <inheritdoc /> /// <inheritdoc />

View file

@ -175,6 +175,13 @@ namespace MLEM.Ui.Elements {
this.CanBeMoused = false; 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 /> /// <inheritdoc />
protected override Vector2 CalcActualSize(RectangleF parentArea) { protected override Vector2 CalcActualSize(RectangleF parentArea) {
var size = base.CalcActualSize(parentArea); var size = base.CalcActualSize(parentArea);
@ -182,6 +189,9 @@ namespace MLEM.Ui.Elements {
this.TokenizeIfNecessary(); this.TokenizeIfNecessary();
this.AlignAndSplitIfNecessary(size); this.AlignAndSplitIfNecessary(size);
var textSize = this.tokenizedText.GetArea(Vector2.Zero, this.TextScale * this.TextScaleMultiplier * this.Scale).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); return new Vector2(this.AutoAdjustWidth ? textSize.X + this.ScaledPadding.Width : size.X, textSize.Y + this.ScaledPadding.Height);
} }
@ -255,7 +265,7 @@ namespace MLEM.Ui.Elements {
var width = size.X - this.ScaledPadding.Width; var width = size.X - this.ScaledPadding.Width;
var scale = this.TextScale * this.TextScaleMultiplier * this.Scale; var scale = this.TextScale * this.TextScaleMultiplier * this.Scale;
if (this.lastAlignSplitWidth == width && this.lastAlignSplitScale == scale) if (this.lastAlignSplitWidth?.Equals(width, Element.Epsilon) == true && this.lastAlignSplitScale?.Equals(scale, Element.Epsilon) == true)
return; return;
this.lastAlignSplitWidth = width; this.lastAlignSplitWidth = width;
this.lastAlignSplitScale = scale; this.lastAlignSplitScale = scale;

View file

@ -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)) {

View file

@ -3,31 +3,31 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"dotnet-mgcb": { "dotnet-mgcb": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb" "mgcb"
] ]
}, },
"dotnet-mgcb-editor": { "dotnet-mgcb-editor": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor" "mgcb-editor"
] ]
}, },
"dotnet-mgcb-editor-linux": { "dotnet-mgcb-editor-linux": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-linux" "mgcb-editor-linux"
] ]
}, },
"dotnet-mgcb-editor-windows": { "dotnet-mgcb-editor-windows": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-windows" "mgcb-editor-windows"
] ]
}, },
"dotnet-mgcb-editor-mac": { "dotnet-mgcb-editor-mac": {
"version": "3.8.1.263", "version": "3.8.1.303",
"commands": [ "commands": [
"mgcb-editor-mac" "mgcb-editor-mac"
] ]

View file

@ -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) {