Пример #1
0
        public bool TryGetValue <T> (StylezStyle style, int propertyNameHashId, out T value)
        {
            var property = Search(style, propertyNameHashId) as StylePropertyValue <T>;

            if (null == property)
            {
                value = default(T);
                return(false);
            }

            value = property.value;
            return(true);
        }
Пример #2
0
        private StylezPropertyValue Search(StylezStyle style, int propertyId)
        {
            if (null == _properties)
            {
                BuildPropertyDictionary();
            }

            if (!_properties.TryGetValue(propertyId, out var properties))
            {
                return(null);
            }

            var propertyValue = Search(properties, MakeSelector(style.idHash, style.state));

            if (propertyValue != null)
            {
                return(propertyValue);
            }

            var state = style.state;

            if (state == StylezState.SelectedHover)
            {
                propertyValue = Search(properties, MakeSelector(style.idHash, StylezState.Hover));
            }

            if (null == propertyValue && state == StylezState.SelectedPressed)
            {
                propertyValue = Search(properties, MakeSelector(style.idHash, StylezState.Pressed));
            }

            if (null == propertyValue && state != StylezState.Normal)
            {
                propertyValue = Search(properties, MakeSelector(style.idHash, StylezState.Normal));
            }

            return(propertyValue);
        }
Пример #3
0
 /// <summary>
 /// Apply this property to the given component
 /// </summary>
 public void Apply(StylezSheet styleSheet, StylezStyle style, Component component) =>
 thunkApply(this, styleSheet, style, component);
Пример #4
0
        private void BuildPropertyDictionary()
        {
            // Populate the dictionary from the serialized values
            _properties   = new Dictionary <int, Dictionary <ulong, StylezPropertyValue> >();
            _selectorBase = new Dictionary <ulong, ulong>();

            if (_styles == null)
            {
                return;
            }

            foreach (var serializedStyle in _styles)
            {
                var styleNameHashId = StylezStyle.StringToHash(serializedStyle.selector.name);
                var selector        = MakeSelector(styleNameHashId, (StylezState)serializedStyle.selector.state);

                // Inheritence
                if (!string.IsNullOrEmpty(serializedStyle.inherit.name))
                {
                    var inheritNameHashId = StylezStyle.StringToHash(serializedStyle.inherit.name);

                    // If both states are "All" then inherit each state individually
                    if (serializedStyle.selector.state == -1 && serializedStyle.inherit.state == -1)
                    {
                        foreach (var state in Enum.GetValues(typeof(StylezState)) as StylezState[])
                        {
                            SetBaseSelector(MakeSelector(styleNameHashId, state), MakeSelector(inheritNameHashId, state));
                        }
                    }

                    // If no state was specified for the selector then set all states for this selector to the same base state
                    else if (serializedStyle.selector.state == -1)
                    {
                        var baseSelector = MakeSelector(inheritNameHashId, (StylezState)serializedStyle.inherit.state);
                        foreach (var state in Enum.GetValues(typeof(StylezState)) as StylezState[])
                        {
                            SetBaseSelector(MakeSelector(styleNameHashId, state), baseSelector);
                        }
                    }

                    // If no state was specified for the base then use the normal state
                    else if (serializedStyle.inherit.state == -1)
                    {
                        SetBaseSelector(selector, MakeSelector(inheritNameHashId, StylezState.Normal));
                    }

                    // Inerit one state from another..
                    else
                    {
                        SetBaseSelector(selector, MakeSelector(inheritNameHashId, (StylezState)serializedStyle.inherit.state));
                    }
                }

                foreach (var serializedProperty in serializedStyle.properties)
                {
                    var propertyNameHashId = StylezStyle.StringToHash(serializedProperty.name);
                    if (!_properties.TryGetValue(propertyNameHashId, out var selectors))
                    {
                        selectors = new Dictionary <ulong, StylezPropertyValue>();
                        _properties[propertyNameHashId] = selectors;
                    }

                    if (!StylezStyle._propertyInfos.TryGetValue(propertyNameHashId, out var propertyInfo))
                    {
                        Debug.LogWarning($"Unknown property \"{name}\" in style sheet");
                        return;
                    }

                    var property = propertyInfo.Parse(serializedProperty.value);
                    if (null == property)
                    {
                        return;
                    }

                    selectors[selector] = property;
                }
            }
        }
Пример #5
0
 public bool TryGetValue <T> (StylezStyle style, string propertyName, out T value) =>
 TryGetValue <T>(style, StylezStyle.StringToHash(propertyName), out value);