1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +01:00

Compare commits

..

No commits in common. "02b46269968311b5fd75226160159198a3050e54" and "7a0464e8d64172bf4250a6a0ff32397c2c85be1e" have entirely different histories.

9 changed files with 25 additions and 26 deletions

View file

@ -10,17 +10,12 @@ Jump to version:
- [5.0.0](#500)
## 6.1.0
### MLEM
Improvements
- Improved EnumHelper.GetValues signature to return an array
### MLEM.Ui
Additions
- Added some extension methods for querying Anchor types
Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly
- Close other dropdowns when opening a dropdown
## 6.0.0
### MLEM

View file

@ -69,6 +69,7 @@ namespace Demos {
// create the root panel that all the other components sit on and add it to the ui system
this.root = new Panel(Anchor.Center, new Vector2(80, 100), Vector2.Zero, false, true);
this.root.ScrollBar.SmoothScrolling = true;
// add the root to the demos' ui
this.UiRoot.AddChild(this.root);

View file

@ -42,16 +42,7 @@ namespace MLEM.Ui.Elements {
});
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
this.OnPressed += e => {
this.IsOpen = !this.IsOpen;
// close other dropdowns in the same root when we open
if (this.IsOpen) {
this.Root.Element.AndChildren(o => {
if (o != this && o is Dropdown d && d.IsOpen)
d.IsOpen = false;
});
}
};
this.OnPressed += e => this.IsOpen = !this.IsOpen;
this.GetGamepadNextElement = (dir, usualNext) => {
// Force navigate down to our first child if we're open
if (this.IsOpen && dir == Direction2.Down)

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
@ -27,7 +28,7 @@ namespace MLEM.Ui.Parsers {
/// </remarks>
public class UiMarkdownParser {
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>();
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>().ToArray();
/// <summary>
/// The base path for markdown images, which is prepended to the image link.

View file

@ -12,7 +12,7 @@ namespace MLEM.Input {
/// <summary>
/// All enum values of <see cref="ModifierKey"/>
/// </summary>
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>();
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>().ToArray();
private static readonly Dictionary<ModifierKey, Keys[]> KeysLookup = new Dictionary<ModifierKey, Keys[]> {
{ModifierKey.Shift, new[] {Keys.LeftShift, Keys.RightShift}},
{ModifierKey.Control, new[] {Keys.LeftControl, Keys.RightControl}},

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Microsoft.Xna.Framework.Input;
using MLEM.Misc;
@ -11,7 +12,7 @@ namespace MLEM.Input {
/// <summary>
/// All enum values of <see cref="MouseButton"/>
/// </summary>
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>();
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>().ToArray();
/// <summary>
/// Returns the <see cref="ButtonState"/> of the given mouse button.

View file

@ -71,7 +71,7 @@ namespace MLEM.Misc {
/// <summary>
/// All <see cref="Direction2"/> enum values
/// </summary>
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>();
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>().ToArray();
/// <summary>
/// The <see cref="Direction2.Up"/> through <see cref="Direction2.Left"/> directions
/// </summary>

View file

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Input;
namespace MLEM.Misc {
@ -10,20 +12,19 @@ namespace MLEM.Misc {
/// <summary>
/// All values of the <see cref="Buttons"/> enum.
/// </summary>
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>();
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>().ToArray();
/// <summary>
/// All values of the <see cref="Keys"/> enum.
/// </summary>
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>();
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>().ToArray();
/// <summary>
/// Returns an array containing all of the values of the given enum type.
/// Note that this method is a version-independent equivalent of .NET 5's <c>Enum.GetValues&lt;TEnum&gt;</c>.
/// Returns all of the values of the given enum type.
/// </summary>
/// <typeparam name="T">The type whose enum to get</typeparam>
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
public static T[] GetValues<T>() {
return (T[]) Enum.GetValues(typeof(T));
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
}
}

View file

@ -1,11 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using FontStashSharp;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MLEM.Cameras;
using MLEM.Data;
using MLEM.Data.Content;
using MLEM.Extended.Font;
using MLEM.Extended.Tiled;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting;
@ -17,6 +23,9 @@ using MLEM.Textures;
using MLEM.Ui;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
using MonoGame.Extended;
using MonoGame.Extended.Tiled;
using MonoGame.Extended.ViewportAdapters;
namespace Sandbox;
@ -339,7 +348,7 @@ public class GameImpl : MlemGame {
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
OnUpdated = (e, time) => {
if (Input.IsPressed(Keys.A)) {
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length);
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Count());
Console.WriteLine(e.Anchor);
}
}