< Summary

Class:UIComponents.Scripts.Components.TooltipComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Tooltip/TooltipComponentView.cs
Covered lines:11
Uncovered lines:15
Coverable lines:26
Total lines:70
Line coverage:42.3% (11 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2100%
OnFocus()0%2100%
OnLoseFocus()0%2100%
OnDeselect(...)0%6200%
Show(...)0%2100%
RefreshControl()0%110100%
SetText(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Tooltip/TooltipComponentView.cs

#LineLine coverage
 1using TMPro;
 2using UIComponents.Scripts.Components.Tooltip;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5
 6namespace UIComponents.Scripts.Components
 7{
 8    [SelectionBase, DisallowMultipleComponent]
 9    public class TooltipComponentView : BaseComponentView<TooltipComponentModel>, IDeselectHandler
 10    {
 11        private const int OFFSET = 16;
 12
 13        [SerializeField] private TMP_Text text;
 14
 15        private bool mouseIsOver;
 16
 17        private RectTransform rectTransform;
 7018        private RectTransform rect => rectTransform ??= GetComponent<RectTransform>();
 19
 20        public override void OnEnable()
 21        {
 022            base.OnEnable();
 023            EventSystem.current.SetSelectedGameObject(gameObject);
 024        }
 25
 26        public override void OnFocus()
 27        {
 028            base.OnFocus();
 029            EventSystem.current.SetSelectedGameObject(gameObject);
 030        }
 31
 32        public override void OnLoseFocus()
 33        {
 034            base.OnLoseFocus();
 035            EventSystem.current.SetSelectedGameObject(gameObject);
 036        }
 37
 38        public void OnDeselect(BaseEventData eventData)
 39        {
 040            if (!isFocused)
 041                Hide();
 042        }
 43
 44        public override void Show(bool instant = false)
 45        {
 046            gameObject.SetActive(true);
 047            base.Show(instant);
 048        }
 49
 50        public override void RefreshControl()
 51        {
 3552            SetText(model.message);
 3553            AdjustTooltipSizeToText();
 54
 55            void AdjustTooltipSizeToText()
 56            {
 3557                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, text.preferredWidth + (OFFSET * 2));
 3558                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, text.preferredHeight + (OFFSET * 2));
 3559            }
 3560        }
 61
 62        private void SetText(string newText)
 63        {
 3564            model.message = newText;
 65
 3566            if (text != null)
 3567                text.text = newText;
 3568        }
 69    }
 70}