1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-16 10:44:32 +02:00

some minor code style and format improvements

This commit is contained in:
Ell 2021-03-24 22:44:39 +01:00
parent 281cce8fba
commit 602f19a2a8
11 changed files with 33 additions and 31 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?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"> <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"/> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="MLEM Android Demos"/> <application android:label="MLEM Android Demos" />
</manifest> </manifest>

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">MLEM Android Demos</string> <string name="app_name">MLEM Android Demos</string>
</resources> </resources>

View file

@ -49,8 +49,8 @@ namespace MLEM.Ui.Elements {
this.CanBeSelected = false; this.CanBeSelected = false;
if (scrollOverflow) { if (scrollOverflow) {
var scrollSize = scrollerSize ?? Point.Zero; var (w, h) = scrollerSize ?? Point.Zero;
this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(scrollSize.X, 1), scrollSize.Y, 0) { this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(w, 1), h, 0) {
StepPerScroll = 10, StepPerScroll = 10,
OnValueChanged = (element, value) => this.ScrollChildren(), OnValueChanged = (element, value) => this.ScrollChildren(),
CanAutoAnchorsAttach = false, 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 // 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) 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 // handle automatic element selection, the scroller needs to scroll to the right location
this.OnSelectedElementChanged += (element, otherElement) => { this.OnSelectedElementChanged += (element, otherElement) => {

View file

@ -98,8 +98,8 @@ namespace MLEM.Ui.Elements {
protected override Vector2 CalcActualSize(RectangleF parentArea) { protected override Vector2 CalcActualSize(RectangleF parentArea) {
var size = base.CalcActualSize(parentArea); var size = base.CalcActualSize(parentArea);
this.ParseText(size); this.ParseText(size);
var dims = this.TokenizedText.Measure(this.RegularFont) * this.TextScale * this.TextScaleMultiplier * this.Scale; var (w, h) = 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); return new Vector2(this.AutoAdjustWidth ? w + this.ScaledPadding.Width : size.X, h + this.ScaledPadding.Height);
} }
/// <inheritdoc /> /// <inheritdoc />

View file

@ -84,16 +84,16 @@ namespace MLEM.Ui.Elements {
/// Causes this tooltip's position to be snapped to the mouse position. /// Causes this tooltip's position to be snapped to the mouse position.
/// </summary> /// </summary>
public void SnapPositionToMouse() { 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; var offset = (this.Input.MousePosition.ToVector2() + this.MouseOffset.Value) / this.Scale;
if (offset.X < 0) if (offset.X < 0)
offset.X = 0; offset.X = 0;
if (offset.Y < 0) if (offset.Y < 0)
offset.Y = 0; offset.Y = 0;
if (offset.X * this.Scale + this.Area.Width >= viewport.X) if (offset.X * this.Scale + this.Area.Width >= w)
offset.X = (viewport.X - this.Area.Width) / this.Scale; offset.X = (w - this.Area.Width) / this.Scale;
if (offset.Y * this.Scale + this.Area.Height >= viewport.Y) if (offset.Y * this.Scale + this.Area.Height >= h)
offset.Y = (viewport.Y - this.Area.Height) / this.Scale; offset.Y = (h - this.Area.Height) / this.Scale;
this.PositionOffset = offset; this.PositionOffset = offset;
} }

View file

@ -23,9 +23,9 @@ namespace MLEM.Formatting.Codes {
// don't underline spaces at the end of lines // don't underline spaces at the end of lines
if (c == ' ' && this.Token.DisplayString.Length > indexInToken + 1 && this.Token.DisplayString[indexInToken + 1] == '\n') if (c == ' ' && this.Token.DisplayString.Length > indexInToken + 1 && this.Token.DisplayString[indexInToken + 1] == '\n')
return false; return false;
var size = font.MeasureString(cString) * scale; var (w, h) = font.MeasureString(cString) * scale;
var thicc = size.Y * this.thickness; var t = h * this.thickness;
batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * size.Y - thicc, size.X, thicc), color); batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * h - t, w, t), color);
return false; return false;
} }

View file

@ -39,12 +39,12 @@ namespace MLEM.Misc {
var xDl = down && left ? connectsTo(-1, 1) ? 0 : 4 : left ? 1 : down ? 3 : 2; 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 xDr = down && right ? connectsTo(1, 1) ? 0 : 4 : right ? 1 : down ? 3 : 2;
var size = textureRegion.Size; var (w, h) = textureRegion.Size;
var halfSize = new Point(size.X / 2, size.Y / 2); var (w2, h2) = new Point(w / 2, h / 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, 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 * 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 + 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 * 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, 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 * 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); 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> /// <summary>

View file

@ -179,8 +179,8 @@ namespace MLEM.Misc {
/// <param name="dir">The direction whose angle to get</param> /// <param name="dir">The direction whose angle to get</param>
/// <returns>The direction's angle</returns> /// <returns>The direction's angle</returns>
public static float Angle(this Direction2 dir) { public static float Angle(this Direction2 dir) {
var offset = dir.Offset(); var (x, y) = dir.Offset();
return (float) Math.Atan2(offset.Y, offset.X); return (float) Math.Atan2(y, x);
} }
/// <summary> /// <summary>

View file

@ -64,7 +64,7 @@ namespace Tests {
} }
public override bool Equals(object obj) { 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() { public override int GetHashCode() {