1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +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); 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.")); 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 // 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) // (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.") { 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 Anchor anchor;
private Vector2 size; private Vector2 size;
private Vector2 offset; private Vector2 offset;
public Point Padding; public Vector2 Padding;
public Point ScaledPadding => this.Padding.Multiply(this.Scale); public Point ScaledPadding => (this.Padding * this.Scale).ToPoint();
private Point childPadding; private Vector2 childPadding;
public Anchor Anchor { public Anchor Anchor {
get => this.anchor; get => this.anchor;
set { set {
@ -57,7 +57,7 @@ namespace MLEM.Ui.Elements {
} }
} }
public Point ScaledOffset => (this.offset * this.Scale).ToPoint(); public Point ScaledOffset => (this.offset * this.Scale).ToPoint();
public Point ChildPadding { public Vector2 ChildPadding {
get => this.childPadding; get => this.childPadding;
set { set {
if (this.childPadding == value) if (this.childPadding == value)
@ -67,7 +67,7 @@ namespace MLEM.Ui.Elements {
} }
} }
public Rectangle ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding); 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 DrawCallback OnDrawn;
public TimeCallback OnUpdated; public TimeCallback OnUpdated;
@ -125,8 +125,8 @@ namespace MLEM.Ui.Elements {
} }
} }
public Rectangle Area => this.UnscrolledArea.OffsetCopy(this.ScaledScrollOffset); public Rectangle Area => this.UnscrolledArea.OffsetCopy(this.ScaledScrollOffset);
public Point ScrollOffset; public Vector2 ScrollOffset;
public Point ScaledScrollOffset => this.ScrollOffset.Multiply(this.Scale); public Point ScaledScrollOffset => (this.ScrollOffset * this.Scale).ToPoint();
public Rectangle DisplayArea => this.Area.Shrink(this.ScaledPadding); public Rectangle DisplayArea => this.Area.Shrink(this.ScaledPadding);
private int priority; private int priority;
public int Priority { public int Priority {

View file

@ -5,9 +5,9 @@ using MLEM.Textures;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
public static class ElementHelper { 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 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.OnAreaUpdated += e => image.Size = new Vector2(e.Area.Height, e.Area.Height) / e.Scale;
button.AddChild(image, 0); button.AddChild(image, 0);
return button; return button;

View file

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

View file

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