< 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:11
Coverable lines:31
Total lines:95
Line coverage:64.5% (20 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%2100%
RecalculateColumnsSize()0%7.017094.12%
RegisterCurrentColumns()0%330100%
RefreshAllChildUIComponentsSize()0%13.264016.67%

File(s)

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

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public interface IColumnsOrganizerComponentView
 8{
 9    /// <summary>
 10    /// Recalculates the size of each columns following the configuration in the model.
 11    /// </summary>
 12    void RecalculateColumnsSize();
 13}
 14
 15public class ColumnsOrganizerComponentView : BaseComponentView, IColumnsOrganizerComponentView
 16{
 17    [Header("Prefab References")]
 18    [SerializeField] internal HorizontalLayoutGroup horizontalLayoutGroup;
 19    [SerializeField] internal RectTransform columnsContainer;
 20
 21    [Header("Configuration")]
 22    [SerializeField] internal ColumnsOrganizerComponentModel model;
 23
 6924    internal List<RectTransform> currentColumns = new List<RectTransform>();
 25
 26    public override void RefreshControl()
 27    {
 028        if (model == null)
 029            return;
 30
 031        RecalculateColumnsSize();
 032    }
 33
 34    public override void OnScreenSizeChanged()
 35    {
 036        base.OnScreenSizeChanged();
 37
 038        RecalculateColumnsSize();
 039    }
 40
 41    public void RecalculateColumnsSize()
 42    {
 143        RegisterCurrentColumns();
 44
 145        horizontalLayoutGroup.spacing = model.spaceBetweenColumns;
 46
 647        float totalWidthOfFixedSizeColumns = model.columnsConfig.Where(x => !x.isPercentage).Sum(x => x.width);
 148        float totalWidthOfPercentageColumns = columnsContainer.rect.width - totalWidthOfFixedSizeColumns - (model.spaceB
 49
 850        for (int i = 0; i < currentColumns.Count; i++)
 51        {
 352            if (model.columnsConfig.Count - 1 >= i)
 53            {
 354                if (model.columnsConfig[i].isPercentage)
 55                {
 156                    float newWidth = totalWidthOfPercentageColumns * model.columnsConfig[i].width / 100f;
 157                    if (newWidth < 0)
 058                        newWidth = 0;
 59
 160                    currentColumns[i].sizeDelta = new Vector2(
 61                        newWidth,
 62                        currentColumns[i].sizeDelta.y);
 163                }
 64                else
 65                {
 266                    currentColumns[i].sizeDelta = new Vector2(
 67                        model.columnsConfig[i].width,
 68                        currentColumns[i].sizeDelta.y);
 69                }
 70            }
 71        }
 72
 173        StartCoroutine(RefreshAllChildUIComponentsSize());
 174    }
 75
 76    internal void RegisterCurrentColumns()
 77    {
 178        currentColumns.Clear();
 79
 880        foreach (RectTransform child in transform)
 81        {
 382            currentColumns.Add(child);
 83        }
 184    }
 85
 86    internal IEnumerator RefreshAllChildUIComponentsSize()
 87    {
 188        yield return null;
 89
 090        for (int i = 0; i < model.uiComponentsToRefreshSize.Count; i++)
 91        {
 092            model.uiComponentsToRefreshSize[i].OnScreenSizeChanged();
 93        }
 094    }
 95}