#aligning boxes making my own box modell

1 messages · Page 1 of 1 (latest)

grand heart
#

 
public class MyBounds
{
    public float[] corners;



    public MyBounds(float xMin, float xMax, float yMin, float yMax)
    {
        corners = new float[4];
        this.corners[0] = xMin;
        this.corners[2] = yMin;
        this.corners[1] = xMax;
        this.corners[3] = yMax;
    }
    public float width => corners[1] - corners[0];
    public float height => corners[3] - corners[2];
    public float2 topL => new float2(corners[0], corners[3]);
    public float2 topR => new float2(corners[1], corners[3]);
    public float2 btmL => new float2(corners[0], corners[2]);
    public float2 btmR => new float2(corners[1], corners[2]);

    public static MyBounds undefined => new MyBounds(0, 0, 0, 0);

    
#
public static MyBounds Evaluate(MyBounds parent, Container container)
    {

        float matWidth = alignMatrix[(int)container.align * 2];
        float matHeight = alignMatrix[(int)container.align * 2 + 1];

        float matOffsetX = offsetMatrix[(int)container.align * 2];
        float matOffsetY = offsetMatrix[(int)container.align * 2 + 1];

        float offsetx, offsety, width, height;

        if (container.absolute[0]) offsetx = container.xPos;
        else offsetx = container.xPos / 100 * parent.width;

        if (container.absolute[1]) offsety = container.yPos;
        else offsety = container.yPos / 100 * parent.height;

        if (container.absolute[2]) width = container.width;
        else width = container.width / 100 * parent.width;

        if (container.absolute[2]) height = container.width;
        else height = container.height / 100 * parent.height;


        offsetx *= matOffsetX;
        offsety *= matOffsetY;


        float xMin = parent.corners[0] + offsetx + parent.width * matWidth - width * matWidth;
        float yMax = parent.corners[3] + offsety + parent.height * matHeight - height * matHeight;
        float xMax = xMin + width;
        float yMin = yMax - height;
        return new MyBounds(xMin, xMax, yMin, yMax);

    }
    public float xMin
    {
        set
        {
            corners[0] = value;
        }
        get
        {
            return corners[0];
        }
    }
    public float xMax
    {
        set
        {
            corners[1] = value;
        }
        get
        {
            return corners[1];
        }
    }
    public float yMin
    {
        set
        {
            corners[2] = value;
        }
        get
        {
            return corners[2];
        }
    }
    public float yMax
    {
        set
        {
            corners[3] = value;
        }
        get
        {
            return corners[3];
        }
    }