< 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:51
Uncovered lines:3
Coverable lines:54
Total lines:128
Line coverage:94.4% (51 of 54)
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            MarkLayoutDirty( () =>
 62                {
 1263                    referencesContainer.fitter.RefreshRecursively();
 1264                    AdjustChildHook();
 1265                    referencesContainer.scrollRect.Rebuild(CanvasUpdate.MaxUpdateValue);
 1266                }
 67            );
 1268        }
 69
 70        void AdjustChildHook()
 71        {
 2472            UIScrollRectRefContainer rc = referencesContainer;
 2473            rc.childHookRectTransform.SetParent(rc.layoutElementRT, false);
 2474            rc.childHookRectTransform.SetToMaxStretch();
 2475            rc.childHookRectTransform.SetParent(rc.content, true);
 2476            RefreshDCLLayoutRecursively(false, true);
 2477        }
 78
 79        public override void RefreshDCLLayoutRecursively(bool refreshSize = true,
 80            bool refreshAlignmentAndPosition = true)
 81        {
 3682            base.RefreshDCLLayoutRecursively(refreshSize, refreshAlignmentAndPosition);
 3683            referencesContainer.fitter.RefreshRecursively();
 3684        }
 85
 86        public override IEnumerator ApplyChanges(BaseModel newModel)
 87        {
 1288            UIScrollRectRefContainer rc = referencesContainer;
 89
 1290            rc.contentBackground.color = model.backgroundColor;
 91
 92            // Apply padding
 1293            rc.paddingLayoutGroup.padding.bottom = Mathf.RoundToInt(model.paddingBottom);
 1294            rc.paddingLayoutGroup.padding.top = Mathf.RoundToInt(model.paddingTop);
 1295            rc.paddingLayoutGroup.padding.left = Mathf.RoundToInt(model.paddingLeft);
 1296            rc.paddingLayoutGroup.padding.right = Mathf.RoundToInt(model.paddingRight);
 97
 1298            rc.scrollRect.horizontal = model.isHorizontal;
 1299            rc.scrollRect.vertical = model.isVertical;
 100
 12101            rc.HScrollbar.value = model.valueX;
 12102            rc.VScrollbar.value = model.valueY;
 103
 12104            rc.scrollRect.onValueChanged.AddListener(OnChanged);
 105
 12106            MarkLayoutDirty( () =>
 107                {
 12108                    referencesContainer.fitter.RefreshRecursively();
 12109                    AdjustChildHook();
 12110                }
 111            );
 12112            return null;
 113        }
 114
 30115        void OnChanged(Vector2 scrollingValues) { WebInterface.ReportOnScrollChange(scene.sceneData.id, model.OnChanged,
 116
 117        public override void Dispose()
 118        {
 6119            if (referencesContainer != null)
 120            {
 3121                referencesContainer.scrollRect.onValueChanged.RemoveAllListeners();
 3122                Utils.SafeDestroy(referencesContainer.gameObject);
 123            }
 124
 6125            base.Dispose();
 6126        }
 127    }
 128}