< Summary

Class:GDX.VisualElementStyles
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/VisualElementStyles.cs
Covered lines:6
Uncovered lines:39
Coverable lines:45
Total lines:96
Line coverage:13.3% (6 of 45)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:6
Method coverage:16.6% (1 of 6)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
VisualElementStyles()0%110100%
ApplyAlignment(...)0%30500%
Hide(...)0%2100%
IsVisible(...)0%2100%
Fullscreen(...)0%2100%
Show(...)0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/VisualElementStyles.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7using UnityEngine.UIElements;
 8
 9namespace GDX
 10{
 11    public static class VisualElementStyles
 12    {
 13        public const string AlignmentTopLeftClass = "top-left";
 14        public const string AlignmentTopRightClass = "top-right";
 15        public const string AlignmentBottomLeftClass = "bottom-left";
 16        public const string AlignmentBottomRightClass = "bottom-right";
 17
 218        public static readonly StyleEnum<Position> PositionAbsolute = Position.Absolute;
 219        public static readonly StyleEnum<Position> PositionRelative = Position.Relative;
 220        public static readonly StyleEnum<DisplayStyle> DisplayHidden = DisplayStyle.None;
 221        public static readonly StyleEnum<DisplayStyle> DisplayVisible = DisplayStyle.Flex;
 222        public static readonly StyleLength LengthOneHundredPercent = new StyleLength(new Length(100f, LengthUnit.Percent
 223        public static readonly StyleLength LengthZeroPixel = new StyleLength(new Length(0, LengthUnit.Pixel));
 24
 25        public enum Alignment
 26        {
 27            TopLeft = 0,
 28            TopRight = 1,
 29            BottomLeft = 2,
 30            BottomRight = 3
 31        }
 32
 33        public static void ApplyAlignment(this VisualElement element, Alignment alignment)
 034        {
 035            switch (alignment)
 36            {
 37                case Alignment.TopLeft:
 038                    element.EnableInClassList(AlignmentTopRightClass, false);
 039                    element.EnableInClassList(AlignmentBottomLeftClass, false);
 040                    element.EnableInClassList(AlignmentBottomRightClass, false);
 41
 042                    element.EnableInClassList(AlignmentTopLeftClass, true);
 043                    break;
 44                case Alignment.TopRight:
 045                    element.EnableInClassList(AlignmentTopLeftClass, false);
 046                    element.EnableInClassList(AlignmentBottomLeftClass, false);
 047                    element.EnableInClassList(AlignmentBottomRightClass, false);
 48
 049                    element.EnableInClassList(AlignmentTopRightClass, true);
 050                    break;
 51                case Alignment.BottomLeft:
 052                    element.EnableInClassList(AlignmentTopLeftClass, false);
 053                    element.EnableInClassList(AlignmentTopRightClass, false);
 054                    element.EnableInClassList(AlignmentBottomRightClass, false);
 55
 056                    element.EnableInClassList(AlignmentBottomLeftClass, true);
 057                    break;
 58                case Alignment.BottomRight:
 059                    element.EnableInClassList(AlignmentTopLeftClass, false);
 060                    element.EnableInClassList(AlignmentTopRightClass, false);
 061                    element.EnableInClassList(AlignmentBottomLeftClass, false);
 62
 063                    element.EnableInClassList(AlignmentBottomRightClass, true);
 064                    break;
 65            }
 066        }
 67
 68        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 69        public static void Hide(this VisualElement element)
 070        {
 071            element.style.display = DisplayHidden;
 072        }
 73
 74        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 75        public static bool IsVisible(this VisualElement element)
 076        {
 077            return element.style.display == DisplayVisible;
 078        }
 79
 80        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 81        public static void Fullscreen(this VisualElement element)
 082        {
 083            element.style.position = PositionAbsolute;
 084            element.style.width = LengthOneHundredPercent;
 085            element.style.height = LengthOneHundredPercent;
 086            element.style.left = LengthZeroPixel;
 087            element.style.top = LengthZeroPixel;
 088        }
 89
 90        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 91        public static void Show(this VisualElement element)
 092        {
 093            element.style.display = DisplayVisible;
 094        }
 95    }
 96}