< Summary

Class:DCL.Components.UIScrollRect
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIScrollRect/UIScrollRect.cs
Covered lines:49
Uncovered lines:3
Coverable lines:52
Total lines:122
Line coverage:94.2% (49 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
UIScrollRect()0%110100%
AttachTo(...)0%2100%
DetachFrom(...)0%2100%
OnChildAttached(...)0%110100%
OnChildDetached(...)0%110100%
RefreshContainerForShape(...)0%110100%
AdjustChildHook()0%110100%
RefreshDCLLayoutRecursively(...)0%110100%
ApplyChanges(...)0%110100%
OnChanged(...)0%110100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIScrollRect/UIScrollRect.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using DCL.Interface;
 4using DCL.Models;
 5using System.Collections;
 6using System.Collections.Generic;
 7using UnityEngine;
 8using UnityEngine.UI;
 9using Color = UnityEngine.Color;
 10
 11namespace DCL.Components
 12{
 13    public class UIScrollRect : UIShape<UIScrollRectRefContainer, UIScrollRect.Model>
 14    {
 15        [System.Serializable]
 16        new public class Model : UIShape.Model
 17        {
 18            public float valueX = 0;
 19            public float valueY = 0;
 2620            public Color borderColor = Color.white;
 2621            public Color backgroundColor = Color.clear;
 22            public bool isHorizontal = false;
 2623            public bool isVertical = true;
 24            public float paddingTop = 0f;
 25            public float paddingRight = 0f;
 26            public float paddingBottom = 0f;
 27            public float paddingLeft = 0f;
 28            public string OnChanged;
 29
 830            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 31        }
 32
 533        public override string referencesContainerPrefabName => "UIScrollRect";
 34
 1535        public UIScrollRect() { model = new Model(); }
 36
 37        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 38        {
 039            Debug.LogError(
 40                "Aborted UIScrollRectShape attachment to an entity. UIShapes shouldn't be attached to entities.");
 041        }
 42
 043        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { }
 44
 45        public override void OnChildAttached(UIShape parent, UIShape childComponent)
 46        {
 947            base.OnChildAttached(parent, childComponent);
 948            childComponent.OnAppliedChanges -= RefreshContainerForShape;
 949            childComponent.OnAppliedChanges += RefreshContainerForShape;
 950            RefreshContainerForShape(childComponent);
 951        }
 52
 53        public override void OnChildDetached(UIShape parent, UIShape childComponent)
 54        {
 455            base.OnChildDetached(parent, childComponent);
 456            childComponent.OnAppliedChanges -= RefreshContainerForShape;
 457        }
 58
 59        void RefreshContainerForShape(BaseDisposable updatedComponent)
 60        {
 1261            RefreshAll();
 1262            referencesContainer.fitter.RefreshRecursively();
 1263            AdjustChildHook();
 1264            referencesContainer.scrollRect.Rebuild(CanvasUpdate.MaxUpdateValue);
 1265        }
 66
 67        void AdjustChildHook()
 68        {
 2469            UIScrollRectRefContainer rc = referencesContainer;
 2470            rc.childHookRectTransform.SetParent(rc.layoutElementRT, false);
 2471            rc.childHookRectTransform.SetToMaxStretch();
 2472            rc.childHookRectTransform.SetParent(rc.content, true);
 2473            RefreshDCLLayoutRecursively(false, true);
 2474        }
 75
 76        public override void RefreshDCLLayoutRecursively(bool refreshSize = true,
 77            bool refreshAlignmentAndPosition = true)
 78        {
 4879            base.RefreshDCLLayoutRecursively(refreshSize, refreshAlignmentAndPosition);
 4880            referencesContainer.fitter.RefreshRecursively();
 4881        }
 82
 83        public override IEnumerator ApplyChanges(BaseModel newModel)
 84        {
 1285            UIScrollRectRefContainer rc = referencesContainer;
 86
 1287            rc.contentBackground.color = model.backgroundColor;
 88
 89            // Apply padding
 1290            rc.paddingLayoutGroup.padding.bottom = Mathf.RoundToInt(model.paddingBottom);
 1291            rc.paddingLayoutGroup.padding.top = Mathf.RoundToInt(model.paddingTop);
 1292            rc.paddingLayoutGroup.padding.left = Mathf.RoundToInt(model.paddingLeft);
 1293            rc.paddingLayoutGroup.padding.right = Mathf.RoundToInt(model.paddingRight);
 94
 1295            rc.scrollRect.horizontal = model.isHorizontal;
 1296            rc.scrollRect.vertical = model.isVertical;
 97
 1298            rc.HScrollbar.value = model.valueX;
 1299            rc.VScrollbar.value = model.valueY;
 100
 12101            rc.scrollRect.onValueChanged.AddListener(OnChanged);
 102
 12103            RefreshAll();
 12104            referencesContainer.fitter.RefreshRecursively();
 12105            AdjustChildHook();
 12106            return null;
 107        }
 108
 30109        void OnChanged(Vector2 scrollingValues) { WebInterface.ReportOnScrollChange(scene.sceneData.id, model.OnChanged,
 110
 111        public override void Dispose()
 112        {
 6113            if (referencesContainer != null)
 114            {
 3115                referencesContainer.scrollRect.onValueChanged.RemoveAllListeners();
 3116                Utils.SafeDestroy(referencesContainer.gameObject);
 117            }
 118
 6119            base.Dispose();
 6120        }
 121    }
 122}