Example #1
0
        // update list of children and set their layout parent accordingly
        public void SetChildren(LightList <AwesomeLayoutBox> layoutBoxes)
        {
            firstChild = null;
            childCount = layoutBoxes.size;
            if (childCount > 0)
            {
                LayoutResult result = element.layoutResult;
                firstChild        = layoutBoxes[0];
                firstChild.parent = this;
                firstChild.element.layoutResult.layoutParent = result;

                for (int i = 0; i < layoutBoxes.size; i++)
                {
                    layoutBoxes.array[i].parent      = this;
                    layoutBoxes.array[i].nextSibling = null;
                    layoutBoxes.array[i].element.layoutResult.layoutParent = result;
                }

                AwesomeLayoutBox ptr = firstChild;
                for (int i = 1; i < layoutBoxes.size; i++)
                {
                    ptr.nextSibling = layoutBoxes.array[i];
                    ptr             = ptr.nextSibling;
                }
            }

            OnChildrenChanged(layoutBoxes);
        }
Example #2
0
        public override void RunLayoutHorizontal(int frameId)
        {
            AwesomeLayoutBox ptr = firstChild;

            float contentAreaWidth = finalWidth - (paddingBorderHorizontalStart + paddingBorderHorizontalEnd);

            float alignment = element.style.AlignItemsHorizontal;

            // SpaceDistribution extraSpace = element.style.DistributeExtraSpaceHorizontal;

            float inset = paddingBorderHorizontalStart;

            while (ptr != null)
            {
                LayoutSize size = default;
                ptr.GetWidths(ref size);
                float clampedWidth = size.Clamped;

                float x               = inset + size.marginStart;
                float originBase      = x;
                float originOffset    = contentAreaWidth * alignment;
                float alignedPosition = originBase + originOffset + (clampedWidth * -alignment);
                ptr.ApplyLayoutHorizontal(x, alignedPosition, size, clampedWidth, contentAreaWidth, LayoutFit.None, frameId);
                ptr = ptr.nextSibling;
            }
        }
Example #3
0
        public override void RunLayoutHorizontal(int frameId)
        {
            float contentAreaWidth = finalWidth - (paddingBorderHorizontalStart + paddingBorderHorizontalEnd);

            float inset = paddingBorderHorizontalStart;

            LayoutSize size = default;

            firstChild.GetWidths(ref size);

            float contentWidth           = size.Clamped;
            float scrollOffsetPercentage = Mathf.Clamp(scrollView.scrollPercentageX, 0, 1);

            float x               = inset + size.marginStart;
            float originBase      = x;
            float originOffset    = contentAreaWidth * scrollOffsetPercentage;
            float alignedPosition = originBase + originOffset + (contentWidth * -scrollOffsetPercentage);

            firstChild.ApplyLayoutHorizontalExplicit(alignedPosition, contentWidth, frameId);
            firstChild.flags |= LayoutBoxFlags.RequiresMatrixUpdate;

            scrollView.scrollPixelAmountX = alignedPosition;

            AwesomeLayoutBox verticalTrack    = element.children.array[1].layoutBox;
            AwesomeLayoutBox verticalHandle   = element.children.array[2].layoutBox;
            AwesomeLayoutBox horizontalTrack  = element.children.array[3].layoutBox;
            AwesomeLayoutBox horizontalHandle = element.children.array[4].layoutBox;

            float trackSize = Mathf.Max(5f, scrollView.trackSize);

            float horizontalWidth = scrollView.verticalScrollingEnabled ? contentAreaWidth - trackSize : contentAreaWidth;

            if (verticalTrack != null && verticalTrack.element.isEnabled)
            {
                verticalTrack.ApplyLayoutHorizontalExplicit(paddingBorderHorizontalStart + paddingBorderHorizontalEnd + contentAreaWidth - trackSize, trackSize, frameId);
                verticalTrack.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (verticalHandle != null && verticalHandle.element.isEnabled)
            {
                verticalHandle.ApplyLayoutHorizontalExplicit(paddingBorderHorizontalStart + paddingBorderHorizontalEnd + contentAreaWidth - trackSize, trackSize, frameId);
                verticalHandle.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (horizontalTrack != null && horizontalTrack.element.isEnabled)
            {
                horizontalTrack.ApplyLayoutHorizontalExplicit(paddingBorderHorizontalStart, horizontalWidth, frameId);
                horizontalTrack.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (horizontalHandle != null && horizontalHandle.element.isEnabled)
            {
                float handleWidth    = (contentAreaWidth / contentWidth) * horizontalWidth;
                float handlePosition = (contentAreaWidth - handleWidth) * scrollOffsetPercentage;
                horizontalHandle.ApplyLayoutHorizontalExplicit(handlePosition + inset, handleWidth, frameId);
                horizontalHandle.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }
        }
Example #4
0
        public override void RunLayoutVertical(int frameId)
        {
            float contentAreaHeight = finalHeight - (paddingBorderVerticalStart + paddingBorderVerticalEnd);

            LayoutSize size = default;

            firstChild.GetHeights(ref size);
            float contentHeight = size.Clamped;

            float inset = paddingBorderVerticalStart;
            float scrollOffsetPercentage = Mathf.Clamp01(scrollView.scrollPercentageY);

            float y               = inset + size.marginStart;
            float originBase      = y;
            float originOffset    = contentAreaHeight * scrollOffsetPercentage;
            float alignedPosition = contentAreaHeight > contentHeight ? originBase : originBase + originOffset + (contentHeight * -scrollOffsetPercentage);

            firstChild.ApplyLayoutVerticalExplicit(alignedPosition, contentHeight, frameId);
            firstChild.flags |= LayoutBoxFlags.RequiresMatrixUpdate;

            scrollView.scrollPixelAmountY = alignedPosition - originBase;

            AwesomeLayoutBox verticalTrack    = element.children.array[1].layoutBox;
            AwesomeLayoutBox verticalHandle   = element.children.array[2].layoutBox;
            AwesomeLayoutBox horizontalTrack  = element.children.array[3].layoutBox;
            AwesomeLayoutBox horizontalHandle = element.children.array[4].layoutBox;

            float trackSize      = Mathf.Max(5f, scrollView.trackSize);
            float verticalHeight = scrollView.verticalScrollingEnabled ? contentAreaHeight - trackSize : contentAreaHeight;

            if (verticalTrack != null && verticalTrack.element.isEnabled)
            {
                verticalTrack.ApplyLayoutVerticalExplicit(inset, contentAreaHeight, frameId);
                verticalTrack.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (verticalHandle != null && verticalHandle.element.isEnabled)
            {
                float handleHeight   = (contentAreaHeight / contentHeight) * verticalHeight;
                float handlePosition = (contentAreaHeight - handleHeight) * scrollOffsetPercentage;
                verticalHandle.ApplyLayoutVerticalExplicit(handlePosition + inset, handleHeight, frameId);
                verticalHandle.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
                verticalHandle.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (horizontalTrack != null && horizontalTrack.element.isEnabled)
            {
                horizontalTrack.ApplyLayoutVerticalExplicit(paddingBorderVerticalStart + contentAreaHeight - trackSize, trackSize, frameId);
                horizontalTrack.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }

            if (horizontalHandle != null && horizontalHandle.element.isEnabled)
            {
                horizontalHandle.ApplyLayoutVerticalExplicit(paddingBorderVerticalStart + contentAreaHeight - trackSize, trackSize, frameId);
                horizontalHandle.flags |= LayoutBoxFlags.RequiresMatrixUpdate;
            }
        }
Example #5
0
 public void Destroy()
 {
     OnDestroy();
     flags       = 0;
     element     = null;
     nextSibling = null;
     firstChild  = null;
     if (parent != null)
     {
         parent.flags |= LayoutBoxFlags.GatherChildren;
         parent        = null;
     }
 }
Example #6
0
        private void HandleTextContentChanged()
        {
            if (ignoreUpdate)
            {
                return;
            }
            flags              |= (LayoutBoxFlags.RequireLayoutHorizontal | LayoutBoxFlags.RequireLayoutHorizontal);
            finalWidth          = -1;
            finalHeight         = -1;
            cachedContentWidth  = -1;
            cachedContentHeight = -1;
            if (textAlreadyDirty)
            {
                return;
            }
            textAlreadyDirty = true;
            AwesomeLayoutBox ptr = parent;

            while (ptr != null)
            {
                // once we hit a block provider we can safely stop traversing since the provider's parent doesn't care about content size changing
                bool stop = (ptr.flags & LayoutBoxFlags.WidthBlockProvider) != 0;
                // can't break out if already flagged for layout because parent of parent might not be and might be content sized
                ptr.flags |= LayoutBoxFlags.RequireLayoutHorizontal;
                ptr.cachedContentWidth = -1;
//                ptr.element.layoutHistory.AddLogEntry(LayoutDirection.Horizontal, -1, LayoutReason.DescendentStyleSizeChanged);
                if (stop)
                {
                    break;
                }
                ptr = ptr.parent;
            }

            ptr = parent;

            while (ptr != null)
            {
                // once we hit a block provider we can safely stop traversing since the provider's parent doesn't care about content size changing
                bool stop = (ptr.flags & LayoutBoxFlags.HeightBlockProvider) != 0;

                // can't break out if already flagged for layout because parent of parent might not be and might be content sized
                ptr.flags |= LayoutBoxFlags.RequireLayoutVertical;
                ptr.cachedContentHeight = -1;
//                ptr.element.layoutHistory.AddLogEntry(LayoutDirection.Vertical, -1, LayoutReason.DescendentStyleSizeChanged);
                if (stop)
                {
                    break;
                }
                ptr = ptr.parent;
            }
        }
Example #7
0
        protected override float ComputeContentHeight()
        {
            AwesomeLayoutBox ptr  = firstChild;
            float            retn = 0f;

            while (ptr != null)
            {
                LayoutSize size = default;
                ptr.GetHeights(ref size);
                float clampedHeight = size.Clamped + size.marginStart + size.marginEnd;
                if (clampedHeight > retn)
                {
                    retn = clampedHeight;
                }
                ptr = ptr.nextSibling;
            }

            return(retn);
        }
Example #8
0
        protected override float ComputeContentWidth()
        {
            AwesomeLayoutBox ptr  = firstChild;
            float            retn = 0f;

            while (ptr != null)
            {
                LayoutSize size = default;
                ptr.GetWidths(ref size);
                // todo clamp to min/max?
                float clampedWidth = size.Clamped + size.marginStart + size.marginEnd;
                if (clampedWidth > retn)
                {
                    retn = clampedWidth;
                }
                ptr = ptr.nextSibling;
            }

            return(retn);
        }
Example #9
0
        public override void RunLayoutVertical(int frameId)
        {
            AwesomeLayoutBox ptr = firstChild;

            float contentAreaHeight = finalHeight - (paddingBorderVerticalStart + paddingBorderVerticalEnd);

            float alignment = element.style.AlignItemsVertical;
            float inset     = paddingBorderVerticalStart;

            while (ptr != null)
            {
                LayoutSize size = default;
                ptr.GetHeights(ref size);
                float clampedHeight = size.Clamped;

                float y               = inset + size.marginStart;
                float originBase      = y;
                float originOffset    = contentAreaHeight * alignment;
                float alignedPosition = originBase + originOffset + (clampedHeight * -alignment);
                ptr.ApplyLayoutVertical(y, alignedPosition, size, clampedHeight, contentAreaHeight, LayoutFit.None, frameId);
                ptr = ptr.nextSibling;
            }
        }