Beispiel #1
0
    public void SizeProperties_OverrideBaseStyleInState()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            UIStyle baseStyle = new UIStyle();
            SetStyleValue(baseStyle, propName, new UIMeasurement(500));

            CallMethod(root.style, setFnName, new UIMeasurement(1500), StyleState.Hover);
            UIStyleGroup group = new UIStyleGroup()
            {
                name   = "Name",
                normal = new UIStyleRunCommand()
                {
                    style = baseStyle
                }
            };
            UIStyleGroupContainer container = new UIStyleGroupContainer(0, "Name", StyleType.Shared, new[] { group });
            root.style.AddStyleGroupContainer(container);
            Assert.AreEqual(new UIMeasurement(500), ComputedValue <UIMeasurement>(root, propName));

            root.style.EnterState(StyleState.Hover);
            Assert.AreEqual(new UIMeasurement(1500), ComputedValue <UIMeasurement>(root, propName));
        };

        RunSizeTests(TestBody);
    }
Beispiel #2
0
    public void IntProperties_OverrideBaseStyle()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            UIStyle baseStyle = new UIStyle();
            SetStyleValue(baseStyle, propName, 5);

            CallMethod(root.style, setFnName, 15, StyleState.Normal);
            UIStyleGroup group = new UIStyleGroup()
            {
                name   = "Name",
                normal = new UIStyleRunCommand()
                {
                    style = baseStyle
                }
            };
            group.styleType = StyleType.Shared;

            UIStyleGroupContainer container = new UIStyleGroupContainer(0, "Name", StyleType.Shared, new[] { group });
            root.style.AddStyleGroupContainer(container);

            Assert.AreEqual(15, ComputedValue <int>(root, propName));

            root.style.RemoveStyleGroupContainer(container);

            Assert.AreEqual(15, ComputedValue <int>(root, propName));
        };

        RunIntTests(TestBody);
    }
Beispiel #3
0
        private void DrawStyleGroup(string fileName, UIStyleGroup group)
        {
            if (group.normal.style != null)
            {
                DrawStyle(fileName, group.name + " [Normal]", group.normal.style);
                DrawRunCommands(group.normal.runCommands);
            }

            if (group.hover.style != default)
            {
                DrawStyle(fileName, group.name + " [Hover]", group.hover.style);
                DrawRunCommands(group.hover.runCommands);
            }

            if (group.focused.style != default)
            {
                DrawStyle(fileName, group.name + " [Focus]", group.focused.style);
                DrawRunCommands(group.focused.runCommands);
            }

            if (group.active.style != default)
            {
                DrawStyle(fileName, group.name + " [Active]", group.active.style);
                DrawRunCommands(group.active.runCommands);
            }
        }
Beispiel #4
0
        private void DrawStyles()
        {
            UIStyleSet styleSet = selectedElement.style;

            List <UIStyleGroupContainer> baseStyles = styleSet.GetBaseStyles();

            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            GUILayout.BeginHorizontal();
            DrawStyleStateButton("Hover", StyleState.Hover);
            DrawStyleStateButton("Focus", StyleState.Focused);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DrawStyleStateButton("Active", StyleState.Active);
            GUILayout.EndHorizontal();

            GUILayout.Space(10f);

            EditorGUIUtility.labelWidth = labelWidth;

            EditorGUILayout.BeginVertical();

            UIStyleGroup instanceStyle = styleSet.GetInstanceStyle();

            if (instanceStyle != null)
            {
                s_Content.text = "Instance";
                DrawStyleGroup("", instanceStyle);
            }

//
            for (int i = 0; i < baseStyles.Count; i++)
            {
                UIStyleGroupContainer container = baseStyles[i];
                s_Content.text = $"{container.name} ({container.styleType.ToString()})";

                for (int j = 0; j < container.groups.Length; j++)
                {
                    DrawStyleGroup(container.styleSheet?.path, container.groups[j]);
                }
            }

            ListPool <UIStyleGroupContainer> .Release(ref baseStyles);

            GUILayout.EndVertical();
        }
Beispiel #5
0
        private UIStyleGroupContainer CompileStyleGroup(StyleRootNode styleRoot, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            UIStyleGroup defaultGroup = new UIStyleGroup();

            defaultGroup.normal = UIStyleRunCommand.CreateInstance();
            defaultGroup.name   = styleRoot.identifier ?? styleRoot.tagName;
            StyleType styleType = styleRoot.tagName != null ? StyleType.Implicit : StyleType.Shared;

            scratchGroupList.size = 0;

            scratchGroupList.Add(defaultGroup);

            CompileStyleGroups(styleRoot, styleType, scratchGroupList, defaultGroup, styleSheetAnimations, uiSoundData);

            return(new UIStyleGroupContainer(styleSheetImporter.NextStyleGroupId, defaultGroup.name, styleType, scratchGroupList.ToArray()));
        }
Beispiel #6
0
        private void CompileStyleGroups(StyleNodeContainer root, StyleType styleType, LightList <UIStyleGroup> groups, UIStyleGroup targetGroup, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            for (int index = 0; index < root.children.Count; index++)
            {
                StyleASTNode node = root.children[index];
                switch (node)
                {
                case SelectNode selectNode:
                    break;

                case PropertyNode propertyNode:
                    // add to normal ui style set
                    StylePropertyMappers.MapProperty(targetGroup.normal.style, propertyNode, context);
                    break;

                case AttributeNodeContainer attribute:
                    if (root is AttributeNodeContainer)
                    {
                        throw new CompileException(attribute, "You cannot nest attribute group definitions.");
                    }

                    UIStyleGroup attributeGroup = new UIStyleGroup();
                    attributeGroup.normal    = UIStyleRunCommand.CreateInstance();
                    attributeGroup.name      = root.identifier;
                    attributeGroup.rule      = MapAttributeContainerToRule(attribute);
                    attributeGroup.styleType = styleType;
                    groups.Add(attributeGroup);
                    CompileStyleGroups(attribute, styleType, groups, attributeGroup, styleSheetAnimations, uiSoundData);

                    break;

                case RunNode runNode:
                    UIStyleRunCommand cmd = new UIStyleRunCommand()
                    {
                        style       = targetGroup.normal.style,
                        runCommands = targetGroup.normal.runCommands ?? new LightList <IRunCommand>(4)
                    };

                    if (runNode.command is AnimationCommandNode animationCommandNode)
                    {
                        MapAnimationCommand(styleSheetAnimations, cmd, animationCommandNode);
                    }
                    else if (runNode.command is SoundCommandNode soundCommandNode)
                    {
                        MapSoundCommand(uiSoundData, cmd, soundCommandNode);
                    }

                    targetGroup.normal = cmd;
                    break;

                case StyleStateContainer styleContainer:
                    if (styleContainer.identifier == "hover")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.hover;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.hover = uiStyleRunCommand;
                    }
                    else if (styleContainer.identifier == "focus")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.focused;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.focused = uiStyleRunCommand;
                    }
                    else if (styleContainer.identifier == "active")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.active;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.active = uiStyleRunCommand;
                    }
                    else
                    {
                        throw new CompileException(styleContainer, $"Unknown style state '{styleContainer.identifier}'. Please use [hover], [focus] or [active] instead.");
                    }

                    break;

                default:
                    throw new CompileException(node, $"You cannot have a {node} at this level.");
                }
            }
        }