< Summary

Class:DCL.SettingsPanelHUD.Sections.SettingsSectionView
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsSectionView.cs
Covered lines:17
Uncovered lines:0
Coverable lines:17
Total lines:73
Line coverage:100% (17 of 17)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
SetActive(...)0%220100%
CreateWidgets()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsSectionView.cs

#LineLine coverage
 1using DCL.SettingsPanelHUD.Widgets;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DCL.SettingsPanelHUD.Sections
 7{
 8    /// <summary>
 9    /// Interface to implement a view for a SECTION.
 10    /// </summary>
 11    public interface ISettingsSectionView
 12    {
 13        string sectionName { get; }
 14
 15        /// <summary>
 16        /// All the needed logic to initializes the SECTION view and put its WIDGETS factory into operation.
 17        /// </summary>
 18        /// <param name="settingsSectionController">Controller that will be associated to this view.</param>
 19        /// <param name="widgets">List of WIDGETS associated to this SECTION.</param>
 20        void Initialize(ISettingsSectionController settingsSectionController, List<SettingsWidgetModel> widgets, string 
 21
 22        /// <summary>
 23        /// Activates/deactivates the SECTION.
 24        /// </summary>
 25        /// <param name="active">True for SECTION activation.</param>
 26        void SetActive(bool active);
 27    }
 28
 29    /// <summary>
 30    /// MonoBehaviour that represents a SECTION view and will act as a factory of WIDGETS.
 31    /// </summary>
 32    public class SettingsSectionView : MonoBehaviour, ISettingsSectionView
 33    {
 34        [SerializeField] private Transform widgetsContainer;
 35        [SerializeField] private ScrollRect scrollRect;
 36
 37        private ISettingsSectionController settingsSectionController;
 38        private List<SettingsWidgetModel> widgets;
 39        private bool isOpen = false;
 40
 241        public string sectionName { get; private set; }
 42
 43        public void Initialize(ISettingsSectionController settingsSectionController, List<SettingsWidgetModel> widgets, 
 44        {
 445            this.settingsSectionController = settingsSectionController;
 446            this.widgets = widgets;
 447            this.sectionName = sectionName;
 48
 449            CreateWidgets();
 450        }
 51
 52        public void SetActive(bool active)
 53        {
 954            gameObject.SetActive(active);
 55
 956            if (!isOpen && active)
 157                scrollRect.verticalNormalizedPosition = 1f;
 58
 959            isOpen = active;
 960        }
 61
 62        private void CreateWidgets()
 63        {
 2064            foreach (SettingsWidgetModel widgetConfig in widgets)
 65            {
 666                var newWidget = Instantiate(widgetConfig.widgetPrefab, widgetsContainer);
 667                newWidget.gameObject.name = $"Widget_{widgetConfig.title}";
 668                var newWidgetController = Instantiate(widgetConfig.widgetController);
 669                settingsSectionController.AddWidget(newWidget, newWidgetController, widgetConfig);
 70            }
 471        }
 72    }
 73}