mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
some minor code style and format improvements
This commit is contained in:
parent
281cce8fba
commit
602f19a2a8
11 changed files with 33 additions and 31 deletions
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.ellpeck.mlem.demos.android" android:versionCode="1" android:versionName="1.0">
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
|
||||
<application android:label="MLEM Android Demos"/>
|
||||
</manifest>
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
|
||||
<application android:label="MLEM Android Demos" />
|
||||
</manifest>
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<string name="app_name">MLEM Android Demos</string>
|
||||
</resources>
|
||||
<string name="app_name">MLEM Android Demos</string>
|
||||
</resources>
|
|
@ -113,7 +113,7 @@ namespace MLEM.Data {
|
|||
if (this.forceSquare)
|
||||
width = height = Math.Max(width, height);
|
||||
this.PackedTexture = new Texture2D(device, width, height);
|
||||
|
||||
|
||||
// copy texture data onto the packed texture
|
||||
stopwatch.Restart();
|
||||
using (var data = this.PackedTexture.GetTextureData()) {
|
||||
|
|
|
@ -49,8 +49,8 @@ namespace MLEM.Ui.Elements {
|
|||
this.CanBeSelected = false;
|
||||
|
||||
if (scrollOverflow) {
|
||||
var scrollSize = scrollerSize ?? Point.Zero;
|
||||
this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(scrollSize.X, 1), scrollSize.Y, 0) {
|
||||
var (w, h) = scrollerSize ?? Point.Zero;
|
||||
this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(w, 1), h, 0) {
|
||||
StepPerScroll = 10,
|
||||
OnValueChanged = (element, value) => this.ScrollChildren(),
|
||||
CanAutoAnchorsAttach = false,
|
||||
|
@ -59,9 +59,9 @@ namespace MLEM.Ui.Elements {
|
|||
};
|
||||
|
||||
// modify the padding so that the scroll bar isn't over top of something else
|
||||
this.ScrollBar.PositionOffset -= new Vector2(scrollSize.X + 1, 0);
|
||||
this.ScrollBar.PositionOffset -= new Vector2(w + 1, 0);
|
||||
if (autoHideScrollbar)
|
||||
this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, scrollSize.X, 0, 0) * (e.IsHidden ? -1 : 1);
|
||||
this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, w, 0, 0) * (e.IsHidden ? -1 : 1);
|
||||
|
||||
// handle automatic element selection, the scroller needs to scroll to the right location
|
||||
this.OnSelectedElementChanged += (element, otherElement) => {
|
||||
|
|
|
@ -98,8 +98,8 @@ namespace MLEM.Ui.Elements {
|
|||
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
||||
var size = base.CalcActualSize(parentArea);
|
||||
this.ParseText(size);
|
||||
var dims = this.TokenizedText.Measure(this.RegularFont) * this.TextScale * this.TextScaleMultiplier * this.Scale;
|
||||
return new Vector2(this.AutoAdjustWidth ? dims.X + this.ScaledPadding.Width : size.X, dims.Y + this.ScaledPadding.Height);
|
||||
var (w, h) = this.TokenizedText.Measure(this.RegularFont) * this.TextScale * this.TextScaleMultiplier * this.Scale;
|
||||
return new Vector2(this.AutoAdjustWidth ? w + this.ScaledPadding.Width : size.X, h + this.ScaledPadding.Height);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -84,16 +84,16 @@ namespace MLEM.Ui.Elements {
|
|||
/// Causes this tooltip's position to be snapped to the mouse position.
|
||||
/// </summary>
|
||||
public void SnapPositionToMouse() {
|
||||
var viewport = this.System.Viewport.Size;
|
||||
var (w, h) = this.System.Viewport.Size;
|
||||
var offset = (this.Input.MousePosition.ToVector2() + this.MouseOffset.Value) / this.Scale;
|
||||
if (offset.X < 0)
|
||||
offset.X = 0;
|
||||
if (offset.Y < 0)
|
||||
offset.Y = 0;
|
||||
if (offset.X * this.Scale + this.Area.Width >= viewport.X)
|
||||
offset.X = (viewport.X - this.Area.Width) / this.Scale;
|
||||
if (offset.Y * this.Scale + this.Area.Height >= viewport.Y)
|
||||
offset.Y = (viewport.Y - this.Area.Height) / this.Scale;
|
||||
if (offset.X * this.Scale + this.Area.Width >= w)
|
||||
offset.X = (w - this.Area.Width) / this.Scale;
|
||||
if (offset.Y * this.Scale + this.Area.Height >= h)
|
||||
offset.Y = (h - this.Area.Height) / this.Scale;
|
||||
this.PositionOffset = offset;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace MLEM.Formatting.Codes {
|
|||
// don't underline spaces at the end of lines
|
||||
if (c == ' ' && this.Token.DisplayString.Length > indexInToken + 1 && this.Token.DisplayString[indexInToken + 1] == '\n')
|
||||
return false;
|
||||
var size = font.MeasureString(cString) * scale;
|
||||
var thicc = size.Y * this.thickness;
|
||||
batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * size.Y - thicc, size.X, thicc), color);
|
||||
var (w, h) = font.MeasureString(cString) * scale;
|
||||
var t = h * this.thickness;
|
||||
batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * h - t, w, t), color);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ namespace MLEM.Misc {
|
|||
var xDl = down && left ? connectsTo(-1, 1) ? 0 : 4 : left ? 1 : down ? 3 : 2;
|
||||
var xDr = down && right ? connectsTo(1, 1) ? 0 : 4 : right ? 1 : down ? 3 : 2;
|
||||
|
||||
var size = textureRegion.Size;
|
||||
var halfSize = new Point(size.X / 2, size.Y / 2);
|
||||
batch.Draw(texture, new Vector2(pos.X, pos.Y), new Rectangle(textureRegion.X + 0 + xUl * size.X, textureRegion.Y + 0, halfSize.X, halfSize.Y), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X + 0.5F * size.X * sc.X, pos.Y), new Rectangle(textureRegion.X + halfSize.X + xUr * size.X, textureRegion.Y + 0, halfSize.X, halfSize.Y), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X, pos.Y + 0.5F * size.Y * sc.Y), new Rectangle(textureRegion.X + xDl * size.X, textureRegion.Y + halfSize.Y, halfSize.X, halfSize.Y), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X + 0.5F * size.X * sc.X, pos.Y + 0.5F * size.Y * sc.Y), new Rectangle(textureRegion.X + halfSize.X + xDr * size.X, textureRegion.Y + halfSize.Y, halfSize.X, halfSize.Y), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
var (w, h) = textureRegion.Size;
|
||||
var (w2, h2) = new Point(w / 2, h / 2);
|
||||
batch.Draw(texture, new Vector2(pos.X, pos.Y), new Rectangle(textureRegion.X + 0 + xUl * w, textureRegion.Y + 0, w2, h2), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X + 0.5F * w * sc.X, pos.Y), new Rectangle(textureRegion.X + w2 + xUr * w, textureRegion.Y + 0, w2, h2), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X, pos.Y + 0.5F * h * sc.Y), new Rectangle(textureRegion.X + xDl * w, textureRegion.Y + h2, w2, h2), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
batch.Draw(texture, new Vector2(pos.X + 0.5F * w * sc.X, pos.Y + 0.5F * h * sc.Y), new Rectangle(textureRegion.X + w2 + xDr * w, textureRegion.Y + h2, w2, h2), color, rotation, org, sc, SpriteEffects.None, layerDepth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -179,8 +179,8 @@ namespace MLEM.Misc {
|
|||
/// <param name="dir">The direction whose angle to get</param>
|
||||
/// <returns>The direction's angle</returns>
|
||||
public static float Angle(this Direction2 dir) {
|
||||
var offset = dir.Offset();
|
||||
return (float) Math.Atan2(offset.Y, offset.X);
|
||||
var (x, y) = dir.Offset();
|
||||
return (float) Math.Atan2(y, x);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -11,14 +11,14 @@ namespace Tests {
|
|||
new[] {'A', 'B'},
|
||||
new[] {'+', '-'}
|
||||
};
|
||||
|
||||
|
||||
var expected = new[] {
|
||||
new[] {'1', 'A', '+'}, new[] {'1', 'A', '-'}, new[] {'1', 'B', '+'}, new[] {'1', 'B', '-'},
|
||||
new[] {'2', 'A', '+'}, new[] {'2', 'A', '-'}, new[] {'2', 'B', '+'}, new[] {'2', 'B', '-'},
|
||||
new[] {'3', 'A', '+'}, new[] {'3', 'A', '-'}, new[] {'3', 'B', '+'}, new[] {'3', 'B', '-'}
|
||||
};
|
||||
Assert.AreEqual(things.Combinations(), expected);
|
||||
|
||||
|
||||
var indices = new[] {
|
||||
new[] {0, 0, 0}, new[] {0, 0, 1}, new[] {0, 1, 0}, new[] {0, 1, 1},
|
||||
new[] {1, 0, 0}, new[] {1, 0, 1}, new[] {1, 1, 0}, new[] {1, 1, 1},
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace Tests {
|
|||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return ReferenceEquals(this, obj) || obj is TestObject other && Equals(other);
|
||||
return ReferenceEquals(this, obj) || obj is TestObject other && this.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
|
|
Loading…
Reference in a new issue