1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

turn some points into vectors for added precision

This commit is contained in:
Ellpeck 2019-09-26 22:16:21 +02:00
parent 84d5d3ab18
commit 36204e40cb
5 changed files with 14 additions and 14 deletions

View file

@ -72,7 +72,7 @@ namespace Demos {
this.UiSystem.Add("Test", root);
root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This is a small demo for MLEM.Ui, a user interface library that is part of (M)LEM (L)ibrary by (E)llpeck for (M)onoGame."));
var image = root.AddChild(new Image(Anchor.AutoCenter, new Vector2(50, 50), new TextureRegion(this.testTexture, 0, 0, 8, 8)) {IsHidden = true, Padding = new Point(3)});
var image = root.AddChild(new Image(Anchor.AutoCenter, new Vector2(50, 50), new TextureRegion(this.testTexture, 0, 0, 8, 8)) {IsHidden = true, Padding = new Vector2(3)});
// Setting the x or y coordinate of the size to 1 or a lower number causes the width or height to be a percentage of the parent's width or height
// (for example, setting the size's x to 0.75 would make the element's width be 0.75*parentWidth)
root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), "Toggle Test Image", "This button shows a grass tile as a test image to show the automatic anchoring of objects.") {

View file

@ -25,9 +25,9 @@ namespace MLEM.Ui.Elements {
private Anchor anchor;
private Vector2 size;
private Vector2 offset;
public Point Padding;
public Point ScaledPadding => this.Padding.Multiply(this.Scale);
private Point childPadding;
public Vector2 Padding;
public Point ScaledPadding => (this.Padding * this.Scale).ToPoint();
private Vector2 childPadding;
public Anchor Anchor {
get => this.anchor;
set {
@ -57,7 +57,7 @@ namespace MLEM.Ui.Elements {
}
}
public Point ScaledOffset => (this.offset * this.Scale).ToPoint();
public Point ChildPadding {
public Vector2 ChildPadding {
get => this.childPadding;
set {
if (this.childPadding == value)
@ -67,7 +67,7 @@ namespace MLEM.Ui.Elements {
}
}
public Rectangle ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding);
public Point ScaledChildPadding => this.childPadding.Multiply(this.Scale);
public Point ScaledChildPadding => (this.childPadding * this.Scale).ToPoint();
public DrawCallback OnDrawn;
public TimeCallback OnUpdated;
@ -125,8 +125,8 @@ namespace MLEM.Ui.Elements {
}
}
public Rectangle Area => this.UnscrolledArea.OffsetCopy(this.ScaledScrollOffset);
public Point ScrollOffset;
public Point ScaledScrollOffset => this.ScrollOffset.Multiply(this.Scale);
public Vector2 ScrollOffset;
public Point ScaledScrollOffset => (this.ScrollOffset * this.Scale).ToPoint();
public Rectangle DisplayArea => this.Area.Shrink(this.ScaledPadding);
private int priority;
public int Priority {

View file

@ -5,9 +5,9 @@ using MLEM.Textures;
namespace MLEM.Ui.Elements {
public static class ElementHelper {
public static Button ImageButton(Anchor anchor, Vector2 size, TextureRegion texture, string text = null, string tooltipText = null, float tooltipWidth = 50, int imagePadding = 2) {
public static Button ImageButton(Anchor anchor, Vector2 size, TextureRegion texture, string text = null, string tooltipText = null, float tooltipWidth = 50, float imagePadding = 2) {
var button = new Button(anchor, size, text, tooltipText, tooltipWidth);
var image = new Image(Anchor.CenterLeft, Vector2.One, texture) {Padding = new Point(imagePadding)};
var image = new Image(Anchor.CenterLeft, Vector2.One, texture) {Padding = new Vector2(imagePadding)};
button.OnAreaUpdated += e => image.Size = new Vector2(e.Area.Height, e.Area.Height) / e.Scale;
button.AddChild(image, 0);
return button;

View file

@ -22,7 +22,7 @@ namespace MLEM.Ui.Elements {
this.PositionOffset = positionOffset;
this.SetHeightBasedOnChildren = setHeightBasedOnChildren;
this.scrollOverflow = scrollOverflow;
this.ChildPadding = new Point(5);
this.ChildPadding = new Vector2(5);
this.CanBeSelected = false;
if (scrollOverflow) {
@ -37,7 +37,7 @@ 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.ChildPadding += new Point(scrollSize.X, 0);
this.ChildPadding += new Vector2(scrollSize.X, 0);
// handle automatic element selection, the scroller needs to scroll to the right location
this.OnSelectedElementChanged += (element, otherElement) => {
@ -92,7 +92,7 @@ namespace MLEM.Ui.Elements {
return;
var offset = -this.ScrollBar.CurrentValue.Floor();
foreach (var child in this.GetChildren(c => c != this.ScrollBar, true))
child.ScrollOffset = new Point(0, offset);
child.ScrollOffset = new Vector2(0, offset);
this.relevantChildrenDirty = true;
}

View file

@ -12,7 +12,7 @@ namespace MLEM.Ui.Elements {
public Tooltip(float width, string text, Element elementToHover = null) :
base(Anchor.TopLeft, width, text) {
this.AutoAdjustWidth = true;
this.Padding = new Point(2);
this.Padding = new Vector2(2);
this.CanBeSelected = false;
if (elementToHover != null) {