< Summary

Class:ColumnsOrganizerComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ColumnsOrganizer/ColumnsOrganizerComponentView.cs
Covered lines:26
Uncovered lines:5
Coverable lines:31
Total lines:98
Line coverage:83.8% (26 of 31)
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%110100%
RecalculateColumnsSize()0%7.017093.75%
RegisterCurrentColumns()0%330100%
RefreshAllChildUIComponentsSize()0%440100%

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
 14025    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    {
 937        base.OnScreenSizeChanged();
 38
 939        RecalculateColumnsSize();
 940    }
 41
 42    public void RecalculateColumnsSize()
 43    {
 1044        RegisterCurrentColumns();
 45
 1046        horizontalLayoutGroup.spacing = model.spaceBetweenColumns;
 47
 4248        float totalWidthOfFixedSizeColumns = model.columnsConfig.Where(x => !x.isPercentage).Sum(x => x.width);
 1049        float totalWidthOfPercentageColumns = columnsContainer.rect.width - totalWidthOfFixedSizeColumns - (model.spaceB
 50
 6251        for (int i = 0; i < currentColumns.Count; i++)
 52        {
 2153            if (model.columnsConfig.Count - 1 >= i)
 54            {
 2155                if (model.columnsConfig[i].isPercentage)
 56                {
 1057                    float newWidth = totalWidthOfPercentageColumns * model.columnsConfig[i].width / 100f;
 1058                    if (newWidth < 0)
 059                        newWidth = 0;
 60
 1061                    currentColumns[i].sizeDelta = new Vector2(
 62                        newWidth,
 63                        currentColumns[i].sizeDelta.y);
 64                }
 65                else
 66                {
 1167                    currentColumns[i].sizeDelta = new Vector2(
 68                        model.columnsConfig[i].width,
 69                        currentColumns[i].sizeDelta.y);
 70                }
 71            }
 72        }
 73
 1074        StartCoroutine(RefreshAllChildUIComponentsSize());
 1075    }
 76
 77    internal void RegisterCurrentColumns()
 78    {
 1079        currentColumns.Clear();
 80
 6281        foreach (RectTransform child in transform)
 82        {
 2183            currentColumns.Add(child);
 84        }
 1085    }
 86
 87    internal IEnumerator RefreshAllChildUIComponentsSize()
 88    {
 1089        yield return null;
 90
 7291        for (int i = 0; i < model.uiComponentsToRefreshSize.Count; i++)
 92        {
 2793            model.uiComponentsToRefreshSize[i].OnScreenSizeChanged();
 94        }
 95
 996        Utils.ForceRebuildLayoutImmediate(transform as RectTransform);
 997    }
 98}