Example #1
0
        public static void setupMargins(ref div div)
        {
            var parentSize = div.parent.element.sizeDelta.x;
            var elSize     = div.element.sizeDelta.x;

            var parentHeight = div.parent.element.sizeDelta.y;
            var elHeight     = div.element.sizeDelta.y;

            if (parentSize > elSize &&
                div.margin[3].auto && div.margin[1].auto) // it means we center this boot horizontally.
            {
                var remainingSpace = parentSize - elSize;
                div.margin[3].floating = remainingSpace / 2;
            }
            else
            {
                div.margin[3].floating = 0;
            }

            if (parentHeight > elHeight &&
                div.margin[0].auto && div.margin[2].auto)
            {
                var remainingSpace = parentHeight - elHeight;
                div.margin[0].floating = remainingSpace / 2;
            }

            div.element.localPosition = new Vector3(div.margin[3].floating, -div.margin[0].floating, 0f);
        }
Example #2
0
        private static void build(div div)
        {
            if (div.type != divType.label)
            {
                BootstrapSize(div.width,
                              div.height,
                              div.element);
            }

            if (div.margin != null)
            {
                setupMargins(ref div);
            }
            else if (div.childIndex == 0)
            {
                div.element.localPosition = new Vector3(0f, 0f, 0f);
            }
            else
            {
                var x = getUsedSpace(div, true);

                if (divFitsInline(x, div.element.sizeDelta.x, div.parent.element.sizeDelta.x))
                {
                    div.element.localPosition = new Vector3(x, 0f, 0f);
                }
                else
                {
                    var y = getUsedSpace(div);
                    div.element.localPosition = new Vector3(0, -y, 0f);
                }
            }
        }
Example #3
0
 public static void buildClass(div div)
 {
     switch (div._class)
     {
     case _class.round_header:
         round_header(div);
         break;
     }
 }
Example #4
0
 public static void buildDiv(div div)
 {
     if (b.isBody(div.elementName) == false)
     {
         build(div);
     }
     if (div.children.Count > 0)
     {
         foreach (div d in div.children)
         {
             buildDiv(d);
         }
     }
 }
Example #5
0
        public static void getDivs(Transform parent, div div)
        {
            if (div.ignoreChildren)
            {
                return;
            }

            // if it has a class
            if (div._class != _class.none)
            {
                return;
            }

            var i = 0;

            foreach (Transform child in parent)
            {
                // TODO: full functionality for borders
                if (child.gameObject.name == "border-top-2")
                {
                    div.border = child.GetComponent <RectTransform>();
                }

                if (style_base.isDiv(child) == false)
                {
                    continue;
                }

                var s = child.GetComponent <style>();

                if (s == null)
                {
                    continue;
                }

                s.Refresh();

                s.Div.childIndex = i;
                s.Div.parent     = div;


                getDivs(child, s.Div);

                div.children.Add(s.Div);

                i++;
            }
        }
Example #6
0
        public static void round_header(div div)
        {
            RectTransform longPart  = null;
            RectTransform emptyPart = null;
            RectTransform smallPart = null;

            foreach (Transform child in div.element.transform)
            {
                switch (child.gameObject.name)
                {
                case "long":
                    longPart = child.GetComponent <RectTransform>();
                    break;

                case "empty":
                    emptyPart = child.GetComponent <RectTransform>();
                    break;

                case "small":
                    smallPart = child.GetComponent <RectTransform>();
                    break;
                }
            }

            Debug.Assert(longPart != null, "longPart != null");
            Debug.Assert(emptyPart != null, "emptyPart != null");
            Debug.Assert(smallPart != null, "smallPart != null");

            var height         = div.element.sizeDelta.y;
            var emptyPartWidth = height * 2;
            var smallPartWidth = height;

            var width = div.element.sizeDelta.x;

            var remainingWidth = width - emptyPartWidth - smallPartWidth;

            //style_utils.GetValuePercent(emptyPartWidth, width);

            longPart.sizeDelta     = new Vector3(remainingWidth, height);
            longPart.localPosition = new Vector3(0, 0, 0);

            emptyPart.sizeDelta     = new Vector3(emptyPartWidth, height);
            emptyPart.localPosition = new Vector3(remainingWidth, 0, 0);

            smallPart.sizeDelta     = new Vector3(smallPartWidth, height);
            smallPart.localPosition = new Vector3(remainingWidth + emptyPartWidth, 0, 0);
        }
Example #7
0
        private static float getOcupiedSpace(div div, out float siblingY, out float biggestSiblingHeight)
        {
            var siblingIndex = div.childIndex - 1;
            var sibling      = div.parent.children;

            siblingY = sibling[siblingIndex].element.localPosition.y;

            biggestSiblingHeight = sibling[siblingIndex].element.sizeDelta.y + sibling[siblingIndex].margin.vertical();

            var space = 0f;

            space += sibling[siblingIndex].element.sizeDelta.x + sibling[siblingIndex].margin.horizontal();

            if (siblingIndex != 0)
            {
                for (var i = siblingIndex - 1; i >= 0; i--)
                {
                    if ((int)sibling[i].element.localPosition.y != (int)siblingY)
                    {
                        continue;
                    }

                    if (biggestSiblingHeight <
                        sibling[i].element.sizeDelta.y + sibling[siblingIndex].margin.vertical())
                    {
                        biggestSiblingHeight = sibling[i].element.sizeDelta.y +
                                               sibling[siblingIndex].margin.vertical();
                    }

                    space += sibling[i].element.sizeDelta.x + sibling[i].margin.horizontal();
                }
            }

            // getting it without the margin
            if (siblingY < 0)
            {
                siblingY = siblingY + sibling[siblingIndex].margin.top().floating;
            }
            else
            {
                siblingY = siblingY - sibling[siblingIndex].margin.top().floating;
            }

            return(space);
        }
Example #8
0
        public static void BootstrapSize(value width, value height, div div)
        {
            var size = b.getParentFreeWidth(div.parent);

            width = b.getValue(width, size);

            // setup the paddings
            div.padding.left().floating  = b.getFValue(div.padding.left(), width.floating);
            div.padding.right().floating = b.getFValue(div.padding.right(), width.floating);

            size   = b.getParentFreeHeight(div.parent);
            height = b.getValue(height, size);

            div.padding.top().floating    = b.getFValue(div.padding.top(), height.floating);
            div.padding.bottom().floating = b.getFValue(div.padding.bottom(), height.floating);

            b.SetFixedSize(width.floating, height.floating, div.element);
        }
Example #9
0
 public static void buildDiv(div div)
 {
     if (div.element.gameObject.activeSelf == false)
     {
         div.element.sizeDelta = new Vector2(0, 0);
         return;
     }
     if (b.isBody(div.elementName) == false)
     {
         build(div);
     }
     if (div.children.Count > 0)
     {
         foreach (div d in div.children)
         {
             buildDiv(d);
         }
     }
 }
Example #10
0
        private static float getUsedSpace(div div, bool xAxis = false)
        {
            if (xAxis)
            {
                float x = 0f;
                for (var i = 0; i < div.childIndex; i++)
                {
                    var blk = div.parent.children[i];
                    x = x + blk.element.sizeDelta.x;
                }

                return(x);
            }

            int          level        = -1;
            List <float> levelsHeight = new List <float>();

            for (var i = 0; i < div.childIndex; i++)
            {
                var blk         = div.parent.children[i];
                var previousBlk = i == 0 ? null : div.parent.children[i - 1];

                if (i == 0 || (int)previousBlk.element.localPosition.y != (int)blk.element.localPosition.y)
                {
                    level++;
                    levelsHeight.Add(blk.element.sizeDelta.y);
                    continue;
                }
                if (previousBlk.element.sizeDelta.y < blk.element.sizeDelta.y)
                {
                    levelsHeight[level] = blk.element.sizeDelta.y;
                }
            }

            float y = 0;

            foreach (float f in levelsHeight)
            {
                y = y + f;
            }
            return(y);
        }
Example #11
0
        private static void build(div div)
        {
            if (div.type == divType.div)
            {
                BootstrapSize(div.width,
                              div.height,
                              div);

                setPosition(ref div);
            }
            else if (div.type == divType.label)
            {
                div.element.anchoredPosition = new Vector3(0f, 0f, 0f);
            }
            else if (div.type == divType.button)
            {
                BootstrapSize(div.width,
                              div.height,
                              div);

                div.element.anchoredPosition3D = new Vector3(0f, 0f, -2f);
                div.element.anchoredPosition   = new Vector2(0f, 0f);
            }

            if (div.border != null)
            {
                // TODO: full functionality for borders
                div.border.sizeDelta     = new Vector3(GetPercent(div.parent.element.sizeDelta.x, 100f), 24f);
                div.border.localPosition = new Vector2(0f, 2f);
            }

            if (div._class != _class.none)
            {
                style_class.buildClass(div);
            }
        }
Example #12
0
 public static float getParentFreeHeight(div p)
 {
     return(p.element.sizeDelta.y - p.padding.vertical());
 }
Example #13
0
 public static float getParentFreeWidth(div p)
 {
     return(p.element.sizeDelta.x - p.padding.horizontal());
 }
Example #14
0
        public static void setPosition(ref div div)
        {
            var parentFreeSize = b.getParentFreeWidth(div.parent);

            var elSize = div.element.sizeDelta.x + div.margin.horizontal();

            if (parentFreeSize >= elSize)
            {
                if (div.margin.left().auto&& div.margin.right().auto)  // it means we center this boot horizontally.
                {
                    var remainingSpace         = parentFreeSize - elSize;
                    div.margin.left().floating = remainingSpace / 2;
                }
                else
                {
                    div.margin.left().floating = b.getFValue(div.margin.left(), parentFreeSize);
                }
            }

            var parentHeight = b.getParentFreeHeight(div.parent);
            var elHeight     = div.element.sizeDelta.y + div.margin.vertical();

            if (parentHeight >= elHeight)
            {
                if (div.margin.top().auto&& div.margin.bottom().auto)
                {
                    var remainingSpace        = parentHeight - elHeight;
                    div.margin.top().floating = remainingSpace / 2;
                }
                else
                {
                    div.margin.top().floating = b.getFValue(div.margin.top(), parentHeight);
                }
            }

            float x = div.margin.left().floating;
            float y = div.margin.top().floating;

            x = x + div.parent.padding.left().floating;

            if (div.childIndex > 0)
            {
                float siblingY;
                float biggestSiblingHeight;
                var   ocupiedSpace = getOcupiedSpace(div, out siblingY, out biggestSiblingHeight);

                siblingY = Mathf.Abs(siblingY);

                // check if this div fits in with the rest.
                //var pS = (int)parentFreeSize;
                if (parentFreeSize < (ocupiedSpace + elSize))   // div doesn't fit move down + the height of its biggest sibling.
                {
                    y = siblingY + y + biggestSiblingHeight;
                }
                else
                {
                    if (siblingY == 0)
                    {
                        y = y + div.parent.padding.top().floating;
                    }

                    x = ocupiedSpace + x;
                    y = siblingY + y;
                }
            }
            else
            {
                y = y + div.parent.padding.top().floating;
            }


            div.element.localPosition = new Vector3(x, -y, 0f);
        }