< Summary

Class:DCL.Components.UIText
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIText/UIText.cs
Covered lines:30
Uncovered lines:4
Coverable lines:34
Total lines:92
Line coverage:88.2% (30 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
UIText()0%110100%
GetClassId()0%2100%
AttachTo(...)0%2100%
DetachFrom(...)0%2100%
ApplyChanges()0%330100%
RefreshDCLSize(...)0%6.016093.75%
Dispose()0%220100%

File(s)

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

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using DCL.Models;
 4using System.Collections;
 5using System.Collections.Generic;
 6using Newtonsoft.Json;
 7using UnityEngine;
 8
 9namespace DCL.Components
 10{
 11    public class UIText : UIShape<UITextReferencesContainer, UIText.Model>
 12    {
 13        [System.Serializable]
 14        new public class Model : UIShape.Model
 15        {
 16            public TextShape.Model textModel;
 17
 4818            public Model() { textModel = new TextShape.Model(); }
 19
 20            public override BaseModel GetDataFromJSON(string json)
 21            {
 422                Model model = Utils.SafeFromJson<Model>(json);
 423                textModel = (TextShape.Model) textModel.GetDataFromJSON(json);
 424                model.textModel = textModel;
 425                return model;
 26            }
 27        }
 28
 429        public override string referencesContainerPrefabName => "UIText";
 30
 1231        public UIText() { model = new Model(); }
 32
 033        public override int GetClassId() { return (int) CLASS_ID.UI_TEXT_SHAPE; }
 34
 035        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) { Debug.LogError("Abo
 36
 037        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { }
 38
 39        public override IEnumerator ApplyChanges(BaseModel newModel)
 40        {
 841            model = (Model) newModel;
 42
 843            yield return TextShape.ApplyModelChanges(scene, referencesContainer.text, model.textModel);
 44
 845            RefreshAll();
 846        }
 47
 48        protected override void RefreshDCLSize(RectTransform parentTransform = null)
 49        {
 1650            if (parentTransform == null)
 51            {
 052                parentTransform = referencesContainer.GetComponentInParent<RectTransform>();
 53            }
 54
 1655            if (model.textModel.adaptWidth || model.textModel.adaptHeight)
 256                referencesContainer.text.ForceMeshUpdate(false);
 57
 1658            Bounds b = referencesContainer.text.textBounds;
 59
 60            float width, height;
 61
 1662            if (model.textModel.adaptWidth)
 63            {
 264                width = b.size.x;
 265            }
 66            else
 67            {
 1468                width = model.width.GetScaledValue(parentTransform.rect.width);
 69            }
 70
 1671            if (model.textModel.adaptHeight)
 72            {
 273                height = b.size.y;
 274            }
 75            else
 76            {
 1477                height = model.height.GetScaledValue(parentTransform.rect.height);
 78            }
 79
 1680            referencesContainer.layoutElementRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
 1681            referencesContainer.layoutElementRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
 1682        }
 83
 84        public override void Dispose()
 85        {
 486            if (referencesContainer != null)
 487                Utils.SafeDestroy(referencesContainer.gameObject);
 88
 489            base.Dispose();
 490        }
 91    }
 92}