< Summary

Class:SliderComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Slider/SliderComponentView.cs
Covered lines:0
Uncovered lines:34
Coverable lines:34
Total lines:133
Line coverage:0% (0 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AddValueToSlider(...)0%2100%
Configure(...)0%2100%
RefreshControl()0%6200%
IsInteractable()0%2100%
SetInteractable(...)0%2100%
SetTextActive(...)0%2100%
SetButtonsActive(...)0%2100%
SetText(...)0%6200%
SetBackground(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Slider/SliderComponentView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public interface ISliderComponentView
 7{
 8    /// <summary>
 9    /// Event that will be triggered when the slider value changes.
 10    /// </summary>
 11    Slider.SliderEvent onSliderChange { get; }
 12
 13    /// <summary>
 14    /// Event that will be triggered when the increment button is clicked.
 15    /// </summary>
 16    Button.ButtonClickedEvent onIncrement { get; }
 17
 18    /// <summary>
 19    /// Event that will be triggered when the decrement button is clicked.
 20    /// </summary>
 21    Button.ButtonClickedEvent onDecrement { get; }
 22
 23    /// <summary>
 24    /// Set the slider text.
 25    /// </summary>
 26    /// <param name="newText">New text.</param>
 27    void SetText(string newText);
 28
 29    /// <summary>
 30    /// Set increment/decrement buttons active
 31    /// </summary>
 32    void SetButtonsActive(bool isActive);
 33
 34    /// <summary>
 35    /// Set slider text active
 36    /// </summary>
 37    /// <param name="isActive">Is active</param>
 38    void SetTextActive(bool isActive);
 39
 40    /// <summary>
 41    /// Set slider background
 42    /// </summary>
 43    /// <param name="image">Background image</param>
 44    void SetBackground(Sprite image);
 45
 46    /// <summary>
 47    /// Set the slider interactable or not.
 48    /// </summary>
 49    /// <param name="isInteractable">Clickable or not</param>
 50    void SetInteractable(bool isInteractable);
 51
 52    /// <summary>
 53    /// Returns true if the slider is Interactable
 54    /// </summary>
 55    bool IsInteractable();
 56}
 57
 58public class SliderComponentView : BaseComponentView, ISliderComponentView, IComponentModelConfig<SliderComponentModel>
 59{
 60
 61    [Header("Prefab References")]
 62    [SerializeField] public Slider slider;
 63    [SerializeField] internal Image background;
 64    [SerializeField] internal TMP_Text text;
 65    [SerializeField] public Button incrementButton;
 66    [SerializeField] public Button decrementButton;
 67
 68    [Header("Configuration")]
 69    [SerializeField] internal SliderComponentModel model;
 70
 071    public Slider.SliderEvent onSliderChange => slider?.onValueChanged;
 072    public Button.ButtonClickedEvent onIncrement => incrementButton?.onClick;
 073    public Button.ButtonClickedEvent onDecrement => decrementButton?.onClick;
 74
 75    public void AddValueToSlider(float value)
 76    {
 077        slider.value += value;
 078    }
 79
 80    public void Configure(SliderComponentModel newModel)
 81    {
 082        model = newModel;
 083        RefreshControl();
 084    }
 85
 86    public override void RefreshControl()
 87    {
 088        if (model == null)
 089            return;
 90
 091        SetButtonsActive(model.areButtonsActive);
 092        SetBackground(model.background);
 093        SetTextActive(model.isTextActive);
 094        SetText(model.text);
 095    }
 96
 097    public bool IsInteractable() { return slider.interactable; }
 98
 099    public void SetInteractable(bool isActive) { slider.interactable = isActive; }
 100
 101    public void SetTextActive(bool isActive)
 102    {
 0103        model.isTextActive = isActive;
 0104        text.gameObject.SetActive(isActive);
 0105    }
 106
 107    public void SetButtonsActive(bool isActive)
 108    {
 0109        model.areButtonsActive = isActive;
 0110        incrementButton.gameObject.SetActive(isActive);
 0111        decrementButton.gameObject.SetActive(isActive);
 0112    }
 113
 114    public void SetText(string newText)
 115    {
 0116        model.text = newText;
 117
 0118        if (text == null)
 0119            return;
 120
 0121        text.text = newText;
 0122    }
 123
 124    public void SetBackground(Sprite image)
 125    {
 0126        model.background = image;
 127
 0128        if (image == null)
 0129            return;
 130
 0131        background.sprite = image;
 0132    }
 133}