< Summary

Class:ColumnsOrganizerComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ColumnsOrganizer/ColumnsOrganizerComponentView.cs
Covered lines:20
Uncovered lines:12
Coverable lines:32
Total lines:98
Line coverage:62.5% (20 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ColumnsOrganizerComponentView()0%110100%
RefreshControl()0%6200%
OnScreenSizeChanged()0%2100%
RecalculateColumnsSize()0%7.017094.12%
RegisterCurrentColumns()0%330100%
RefreshAllChildUIComponentsSize()0%14.074014.29%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ColumnsOrganizer/ColumnsOrganizerComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public interface IColumnsOrganizerComponentView
 9{
 10    /// <summary>
 11    /// Recalculates the size of each columns following the configuration in the model.
 12    /// </summary>
 13    void RecalculateColumnsSize();
 14}
 15
 16public class ColumnsOrganizerComponentView : BaseComponentView, IColumnsOrganizerComponentView
 17{
 18    [Header("Prefab References")]
 19    [SerializeField] internal HorizontalLayoutGroup horizontalLayoutGroup;
 20    [SerializeField] internal RectTransform columnsContainer;
 21
 22    [Header("Configuration")]
 23    [SerializeField] internal ColumnsOrganizerComponentModel model;
 24
 13825    internal List<RectTransform> currentColumns = new List<RectTransform>();
 26
 27    public override void RefreshControl()
 28    {
 029        if (model == null)
 030            return;
 31
 032        RecalculateColumnsSize();
 033    }
 34
 35    public override void OnScreenSizeChanged()
 36    {
 037        base.OnScreenSizeChanged();
 38
 039        RecalculateColumnsSize();
 040    }
 41
 42    public void RecalculateColumnsSize()
 43    {
 144        RegisterCurrentColumns();
 45
 146        horizontalLayoutGroup.spacing = model.spaceBetweenColumns;
 47
 648        float totalWidthOfFixedSizeColumns = model.columnsConfig.Where(x => !x.isPercentage).Sum(x => x.width);
 149        float totalWidthOfPercentageColumns = columnsContainer.rect.width - totalWidthOfFixedSizeColumns - (model.spaceB
 50
 851        for (int i = 0; i < currentColumns.Count; i++)
 52        {
 353            if (model.columnsConfig.Count - 1 >= i)
 54            {
 355                if (model.columnsConfig[i].isPercentage)
 56                {
 157                    float newWidth = totalWidthOfPercentageColumns * model.columnsConfig[i].width / 100f;
 158                    if (newWidth < 0)
 059                        newWidth = 0;
 60
 161                    currentColumns[i].sizeDelta = new Vector2(
 62                        newWidth,
 63                        currentColumns[i].sizeDelta.y);
 164                }
 65                else
 66                {
 267                    currentColumns[i].sizeDelta = new Vector2(
 68                        model.columnsConfig[i].width,
 69                        currentColumns[i].sizeDelta.y);
 70                }
 71            }
 72        }
 73
 174        StartCoroutine(RefreshAllChildUIComponentsSize());
 175    }
 76
 77    internal void RegisterCurrentColumns()
 78    {
 179        currentColumns.Clear();
 80
 881        foreach (RectTransform child in transform)
 82        {
 383            currentColumns.Add(child);
 84        }
 185    }
 86
 87    internal IEnumerator RefreshAllChildUIComponentsSize()
 88    {
 189        yield return null;
 90
 091        for (int i = 0; i < model.uiComponentsToRefreshSize.Count; i++)
 92        {
 093            model.uiComponentsToRefreshSize[i].OnScreenSizeChanged();
 94        }
 95
 096        Utils.ForceRebuildLayoutImmediate(transform as RectTransform);
 097    }
 98}