From 9e2d68061082bf1995ab7d9b1d3197ce52362478 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Sun, 2 Jun 2024 23:16:32 +0200 Subject: [PATCH] renamed padding to margin as that fits better. added individual margin value for all sides --- src/Controls/Container.bf | 20 ++++++++++---------- src/Controls/GuiObject.bf | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Controls/Container.bf b/src/Controls/Container.bf index b33a03a..f4fba74 100644 --- a/src/Controls/Container.bf +++ b/src/Controls/Container.bf @@ -49,30 +49,30 @@ class Container : GuiObject ((Container)e).Reorder(w); for(var i in ((Container)e).Children) { - i.X += x + Padding + e.Padding; - i.Y += y + Padding + e.Padding; + i.X += x + MarginLeft + e.MarginLeft; + i.Y += y + MarginTop + e.MarginTop; } } - if(x+e.Width+e.Padding > w-Padding) //Change both instances of padding to 2*Padding to ensure proper padding on the leftmost side of the screen + if(x+e.Width+e.MarginLeft > w-MarginLeft) //Change both instances of padding to 2*Padding to ensure proper padding on the leftmost side of the screen { //Automatic row break x = 0; y = y + rowHeight; rowHeight = 0; } - e.X = x + e.Padding; - x = x + e.Width + 2*e.Padding; - e.Y = y + e.Padding; + e.X = x + e.MarginLeft; + x = x + e.Width + e.MarginLeft + e.MarginRight; + e.Y = y + e.MarginTop; if(x > maxWidth) maxWidth = x; - if(rowHeight < e.Height+2*e.Padding) - rowHeight = e.Height+2*e.Padding; + if(rowHeight < e.Height+e.MarginTop+e.MarginBottom) + rowHeight = e.Height+e.MarginTop+e.MarginBottom; } - Width = maxWidth + 2*Padding; - Height = y + rowHeight + 2*Padding; + Width = maxWidth + MarginLeft + MarginRight; + Height = y + rowHeight + MarginTop + MarginBottom; } ///Add a new item to the list of items diff --git a/src/Controls/GuiObject.bf b/src/Controls/GuiObject.bf index c86ae71..a8eac03 100644 --- a/src/Controls/GuiObject.bf +++ b/src/Controls/GuiObject.bf @@ -30,11 +30,24 @@ abstract class GuiObject _Parent = value; } }; - public int32 Padding + + ///Margin stuff + public int32 MarginTop = 0; + public int32 MarginBottom = 0; + public int32 MarginLeft = 0; + public int32 MarginRight = 0; + public int32 Margin { - get; - set; - } = 0; + //There seems to be no reasonable way to implement a getter here + set + { + MarginTop = value; + MarginBottom = value; + MarginLeft = value; + MarginRight = value; + } + }; + public int32 X { get; @@ -66,7 +79,7 @@ abstract class GuiObject } public Vector2 SizeOf() { - return .(Width + 2*Padding, Height + 2*Padding); + return .(Width + MarginLeft + MarginRight, Height + MarginTop + MarginBottom); } ///Returns true if the onclick has been handled