renamed padding to margin as that fits better. added individual margin value for all sides

This commit is contained in:
Booklordofthedings 2024-06-02 23:16:32 +02:00
parent b31f61061e
commit 9e2d680610
2 changed files with 28 additions and 15 deletions

View file

@ -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

View file

@ -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