< Summary

Class:DCL.Components.UIScrollRect
Assembly:DCL.Components.UI
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIScrollRect/UIScrollRect.cs
Covered lines:50
Uncovered lines:3
Coverable lines:53
Total lines:127
Line coverage:94.3% (50 of 53)
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 backgroundColor = Color.clear;
 21            public bool isHorizontal = false;
 2622            public bool isVertical = true;
 23            public float paddingTop = 0f;
 24            public float paddingRight = 0f;
 25            public float paddingBottom = 0f;
 26            public float paddingLeft = 0f;
 27            public string OnChanged;
 28
 829            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 30        }
 31
 532        public override string referencesContainerPrefabName => "UIScrollRect";
 33
 1534        public UIScrollRect() { model = new Model(); }
 35
 36        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 37        {
 038            Debug.LogError(
 39                "Aborted UIScrollRectShape attachment to an entity. UIShapes shouldn't be attached to entities.");
 040        }
 41
 042        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { }
 43
 44        public override void OnChildAttached(UIShape parent, UIShape childComponent)
 45        {
 946            base.OnChildAttached(parent, childComponent);
 947            childComponent.OnAppliedChanges -= RefreshContainerForShape;
 948            childComponent.OnAppliedChanges += RefreshContainerForShape;
 949            RefreshContainerForShape(childComponent);
 950        }
 51
 52        public override void OnChildDetached(UIShape parent, UIShape childComponent)
 53        {
 454            base.OnChildDetached(parent, childComponent);
 455            childComponent.OnAppliedChanges -= RefreshContainerForShape;
 456        }
 57
 58        void RefreshContainerForShape(BaseDisposable updatedComponent)
 59        {
 1260            MarkLayoutDirty( () =>
 61                {
 1262                    referencesContainer.fitter.RefreshRecursively();
 1263                    AdjustChildHook();
 1264                    referencesContainer.scrollRect.Rebuild(CanvasUpdate.MaxUpdateValue);
 1265                }
 66            );
 1267        }
 68
 69        void AdjustChildHook()
 70        {
 2471            UIScrollRectRefContainer rc = referencesContainer;
 2472            rc.childHookRectTransform.SetParent(rc.layoutElementRT, false);
 2473            rc.childHookRectTransform.SetToMaxStretch();
 2474            rc.childHookRectTransform.SetParent(rc.content, true);
 2475            RefreshDCLLayoutRecursively(false, true);
 2476        }
 77
 78        public override void RefreshDCLLayoutRecursively(bool refreshSize = true,
 79            bool refreshAlignmentAndPosition = true)
 80        {
 3681            base.RefreshDCLLayoutRecursively(refreshSize, refreshAlignmentAndPosition);
 3682            referencesContainer.fitter.RefreshRecursively();
 3683        }
 84
 85        public override IEnumerator ApplyChanges(BaseModel newModel)
 86        {
 1287            UIScrollRectRefContainer rc = referencesContainer;
 88
 1289            rc.contentBackground.color = model.backgroundColor;
 90
 91            // Apply padding
 1292            rc.paddingLayoutGroup.padding.bottom = Mathf.RoundToInt(model.paddingBottom);
 1293            rc.paddingLayoutGroup.padding.top = Mathf.RoundToInt(model.paddingTop);
 1294            rc.paddingLayoutGroup.padding.left = Mathf.RoundToInt(model.paddingLeft);
 1295            rc.paddingLayoutGroup.padding.right = Mathf.RoundToInt(model.paddingRight);
 96
 1297            rc.scrollRect.horizontal = model.isHorizontal;
 1298            rc.scrollRect.vertical = model.isVertical;
 99
 12100            rc.HScrollbar.value = model.valueX;
 12101            rc.VScrollbar.value = model.valueY;
 102
 12103            rc.scrollRect.onValueChanged.AddListener(OnChanged);
 104
 12105            MarkLayoutDirty( () =>
 106                {
 12107                    referencesContainer.fitter.RefreshRecursively();
 12108                    AdjustChildHook();
 12109                }
 110            );
 12111            return null;
 112        }
 113
 30114        void OnChanged(Vector2 scrollingValues) { WebInterface.ReportOnScrollChange(scene.sceneData.sceneNumber, model.O
 115
 116        public override void Dispose()
 117        {
 1118            if (referencesContainer != null)
 119            {
 1120                referencesContainer.scrollRect.onValueChanged.RemoveAllListeners();
 1121                Utils.SafeDestroy(referencesContainer.gameObject);
 122            }
 123
 1124            base.Dispose();
 1125        }
 126    }
 127}