public VisualElementStylesData(bool isShared)
        {
            this.isShared = isShared;

            // Initialize non trivial properties
            left                          = StyleSheetCache.GetInitialValue(StylePropertyID.PositionLeft).ToStyleLength();
            top                           = StyleSheetCache.GetInitialValue(StylePropertyID.PositionTop).ToStyleLength();
            right                         = StyleSheetCache.GetInitialValue(StylePropertyID.PositionRight).ToStyleLength();
            bottom                        = StyleSheetCache.GetInitialValue(StylePropertyID.PositionBottom).ToStyleLength();
            width                         = StyleSheetCache.GetInitialValue(StylePropertyID.Width).ToStyleLength();
            height                        = StyleSheetCache.GetInitialValue(StylePropertyID.Height).ToStyleLength();
            minWidth                      = StyleSheetCache.GetInitialValue(StylePropertyID.MinWidth).ToStyleLength();
            minHeight                     = StyleSheetCache.GetInitialValue(StylePropertyID.MinHeight).ToStyleLength();
            maxWidth                      = StyleSheetCache.GetInitialValue(StylePropertyID.MaxWidth).ToStyleLength();
            maxHeight                     = StyleSheetCache.GetInitialValue(StylePropertyID.MaxHeight).ToStyleLength();
            alignSelf                     = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignSelf).number;
            alignItems                    = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignItems).number;
            alignContent                  = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignContent).number;
            flexGrow                      = StyleSheetCache.GetInitialValue(StylePropertyID.FlexGrow).ToStyleFloat();
            flexShrink                    = StyleSheetCache.GetInitialValue(StylePropertyID.FlexShrink).ToStyleFloat();
            flexBasis                     = StyleSheetCache.GetInitialValue(StylePropertyID.FlexBasis).ToStyleLength();
            color                         = StyleSheetCache.GetInitialValue(StylePropertyID.Color).color;
            borderLeftColor               = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftColor).color;
            borderTopColor                = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopColor).color;
            borderRightColor              = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightColor).color;
            borderBottomColor             = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomColor).color;
            opacity                       = StyleSheetCache.GetInitialValue(StylePropertyID.Opacity).number;
            unityBackgroundImageTintColor = StyleSheetCache.GetInitialValue(StylePropertyID.BackgroundImageTintColor).color;
        }
示例#2
0
 public static void StyleBorderWidth(this VisualElement ui, StyleFloat left, StyleFloat right, StyleFloat top, StyleFloat bottom)
 {
     ui.style.borderLeftWidth   = left;
     ui.style.borderRightWidth  = right;
     ui.style.borderTopWidth    = top;
     ui.style.borderBottomWidth = bottom;
 }
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleFloat top, out StyleFloat right, out StyleFloat bottom, out StyleFloat left)
        {
            StyleLength styleLength;
            StyleLength styleLength2;
            StyleLength styleLength3;
            StyleLength styleLength4;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out styleLength, out styleLength2, out styleLength3, out styleLength4);
            top    = styleLength.ToStyleFloat();
            right  = styleLength2.ToStyleFloat();
            bottom = styleLength3.ToStyleFloat();
            left   = styleLength4.ToStyleFloat();
        }
示例#4
0
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleFloat top, out StyleFloat right, out StyleFloat bottom, out StyleFloat left)
        {
            StyleLength t;
            StyleLength r;
            StyleLength b;
            StyleLength l;

            CompileBoxAreaNoKeyword(reader, out t, out r, out b, out l);

            top    = t.ToStyleFloat();
            right  = r.ToStyleFloat();
            bottom = b.ToStyleFloat();
            left   = l.ToStyleFloat();
        }
示例#5
0
        public bool TryGetValue(CustomStyleProperty <float> property, out float value)
        {
            CustomPropertyHandle propertyHandle;
            var tmp = new StyleFloat();

            if (TryGetValue(property.name, StyleValueType.Float, out propertyHandle))
            {
                s_StyleSheetApplicator.ApplyFloat(propertyHandle.data, propertyHandle.handles, propertyHandle.specificity, ref tmp);
                value = tmp.value;
                return(true);
            }

            value = 0f;
            return(false);
        }
        internal void ApplyStyleProperty(IStylePropertyReader reader)
        {
            switch (reader.propertyID)
            {
            case StylePropertyID.AlignContent:
                StyleSheetApplicator.ApplyAlign(reader, ref alignContent);
                break;

            case StylePropertyID.AlignItems:
                StyleSheetApplicator.ApplyAlign(reader, ref alignItems);
                break;

            case StylePropertyID.AlignSelf:
                StyleSheetApplicator.ApplyAlign(reader, ref alignSelf);
                break;

            case StylePropertyID.BackgroundImage:
                backgroundImage = reader.ReadStyleBackground(0);
                break;

            case StylePropertyID.FlexBasis:
                flexBasis = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.FlexGrow:
                flexGrow = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.FlexShrink:
                flexShrink = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.Font:
                unityFont = reader.ReadStyleFont(0);
                break;

            case StylePropertyID.FontSize:
                fontSize = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.FontStyleAndWeight:
                unityFontStyleAndWeight = reader.ReadStyleEnum <FontStyle>(0);
                break;

            case StylePropertyID.FlexDirection:
                flexDirection = reader.ReadStyleEnum <FlexDirection>(0);
                break;

            case StylePropertyID.FlexWrap:
                flexWrap = reader.ReadStyleEnum <Wrap>(0);
                break;

            case StylePropertyID.Height:
                height = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.JustifyContent:
                justifyContent = reader.ReadStyleEnum <Justify>(0);
                break;

            case StylePropertyID.MarginLeft:
                marginLeft = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MarginTop:
                marginTop = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MarginRight:
                marginRight = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MarginBottom:
                marginBottom = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MaxHeight:
                maxHeight = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MaxWidth:
                maxWidth = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MinHeight:
                minHeight = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.MinWidth:
                minWidth = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.Overflow:
                overflow = reader.ReadStyleEnum <OverflowInternal>(0);
                break;

            case StylePropertyID.OverflowClipBox:
                unityOverflowClipBox = reader.ReadStyleEnum <OverflowClipBox>(0);
                break;

            case StylePropertyID.PaddingLeft:
                paddingLeft = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PaddingTop:
                paddingTop = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PaddingRight:
                paddingRight = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PaddingBottom:
                paddingBottom = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.Position:
                position = reader.ReadStyleEnum <Position>(0);
                break;

            case StylePropertyID.PositionTop:
                top = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PositionBottom:
                bottom = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PositionLeft:
                left = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.PositionRight:
                right = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.UnityTextAlign:
                unityTextAlign = reader.ReadStyleEnum <TextAnchor>(0);
                break;

            case StylePropertyID.Color:
                color = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.Width:
                width = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.WhiteSpace:
                whiteSpace = reader.ReadStyleEnum <WhiteSpace>(0);
                break;

            case StylePropertyID.BackgroundColor:
                backgroundColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BackgroundScaleMode:
                unityBackgroundScaleMode = reader.ReadStyleEnum <ScaleMode>(0);
                break;

            case StylePropertyID.BackgroundImageTintColor:
                unityBackgroundImageTintColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BorderLeftColor:
                borderLeftColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BorderTopColor:
                borderTopColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BorderRightColor:
                borderRightColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BorderBottomColor:
                borderBottomColor = reader.ReadStyleColor(0);
                break;

            case StylePropertyID.BorderLeftWidth:
                borderLeftWidth = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.BorderTopWidth:
                borderTopWidth = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.BorderRightWidth:
                borderRightWidth = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.BorderBottomWidth:
                borderBottomWidth = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.BorderTopLeftRadius:
                borderTopLeftRadius = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.BorderTopRightRadius:
                borderTopRightRadius = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.BorderBottomRightRadius:
                borderBottomRightRadius = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.BorderBottomLeftRadius:
                borderBottomLeftRadius = reader.ReadStyleLength(0);
                break;

            case StylePropertyID.Cursor:
                cursor = reader.ReadStyleCursor(0);
                break;

            case StylePropertyID.SliceLeft:
                unitySliceLeft = reader.ReadStyleInt(0);
                break;

            case StylePropertyID.SliceTop:
                unitySliceTop = reader.ReadStyleInt(0);
                break;

            case StylePropertyID.SliceRight:
                unitySliceRight = reader.ReadStyleInt(0);
                break;

            case StylePropertyID.SliceBottom:
                unitySliceBottom = reader.ReadStyleInt(0);
                break;

            case StylePropertyID.Opacity:
                opacity = reader.ReadStyleFloat(0);
                break;

            case StylePropertyID.Visibility:
                visibility = reader.ReadStyleEnum <Visibility>(0);
                break;

            case StylePropertyID.Display:
                StyleSheetApplicator.ApplyDisplay(reader, ref display);
                break;

            default:
                throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", reader.propertyID));
            }
        }
示例#7
0
 public static void StyleFlexGrow(this VisualElement ui, StyleFloat grow) => ui.style.flexGrow = grow;
示例#8
0
 public static void StyleBorderWidth(this VisualElement ui, StyleFloat width) => ui.StyleBorderWidth(width, width, width, width);
        private static bool CompileFlexShorthand(StyleSheet sheet, StyleValueHandle[] handles, int specificity, out StyleFloat grow, out StyleFloat shrink, out StyleLength basis)
        {
            grow   = 0f;
            shrink = 1f;
            basis  = StyleKeyword.Auto;

            bool valid = false;

            if (handles.Length == 1 && handles[0].valueType == StyleValueType.Keyword)
            {
                // Handle none | auto
                if (handles[0].valueIndex == (int)StyleValueKeyword.None)
                {
                    valid  = true;
                    grow   = 0f;
                    shrink = 0f;
                    basis  = StyleKeyword.Auto;
                }
                else if (handles[0].valueIndex == (int)StyleValueKeyword.Auto)
                {
                    valid  = true;
                    grow   = 1f;
                    shrink = 1f;
                    basis  = StyleKeyword.Auto;
                }
            }
            else if (handles.Length <= 3)
            {
                // Handle [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
                valid = true;

                grow   = 0f;
                shrink = 1f;
                basis  = Length.Percent(0);

                bool growFound  = false;
                bool basisFound = false;
                for (int i = 0; i < handles.Length && valid; i++)
                {
                    var handle    = handles[i];
                    var valueType = handle.valueType;
                    if (valueType == StyleValueType.Dimension || valueType == StyleValueType.Keyword)
                    {
                        // Basis
                        if (basisFound)
                        {
                            valid = false;
                            break;
                        }

                        basisFound = true;
                        if (valueType == StyleValueType.Keyword)
                        {
                            if (handle.valueIndex == (int)StyleValueKeyword.Auto)
                            {
                                basis = StyleKeyword.Auto;
                            }
                        }
                        else if (valueType == StyleValueType.Dimension)
                        {
                            basis = sheet.ReadStyleLength(handle, specificity);
                        }

                        if (growFound && i != handles.Length - 1)
                        {
                            // If grow is already processed basis must be the last value
                            valid = false;
                        }
                    }
                    else if (valueType == StyleValueType.Float)
                    {
                        var value = sheet.ReadFloat(handle);
                        if (!growFound)
                        {
                            growFound = true;
                            grow      = value;
                        }
                        else
                        {
                            shrink = value;
                        }
                    }
                    else
                    {
                        valid = false;
                    }
                }
            }

            grow.specificity   = specificity;
            shrink.specificity = specificity;
            basis.specificity  = specificity;
            return(valid);
        }
        public void ApplyFloat(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleFloat property)
        {
            var value = sheet.ReadStyleFloat(handles[0], specificity);

            property.Apply(value, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
        }
示例#11
0
        private void DrawProperties()
        {
            EditorGUILayout.LabelField(Styles.elementStylesContent, Styles.KInspectorTitle);

            m_SelectedElement.name = EditorGUILayout.TextField("Name", m_SelectedElement.name);
            EditorGUILayout.LabelField("Debug Id", m_SelectedElement.controlid.ToString());
            var textElement = m_SelectedElement as ITextElement;

            if (textElement != null)
            {
                textElement.text = EditorGUILayout.TextField("Text", textElement.text);
            }

            bool cacheContents = EditorGUILayout.Toggle("Cache Contents", m_SelectedElement.cacheAsBitmap);

            m_SelectedElement.cacheAsBitmap = cacheContents;
            if (m_SelectedElement.cacheAsBitmap && m_SelectedElement.computedStyle.overflow.value == Overflow.Visible)
            {
                EditorGUILayout.HelpBox("Bitmap caching will be ignored for this element because it's not clipped", MessageType.Warning);
            }

            m_SelectedElement.pickingMode = (PickingMode)EditorGUILayout.EnumPopup("Picking Mode", m_SelectedElement.pickingMode);

            if (m_SelectedElement.pseudoStates != 0)
            {
                EditorGUILayout.LabelField("Pseudo States", m_SelectedElement.pseudoStates.ToString());
            }
            else
            {
                EditorGUILayout.LabelField("Pseudo States", "None");
            }

            EditorGUILayout.LabelField("Focusable", m_SelectedElement.focusable.ToString());

            EditorGUILayout.LabelField("Layout", m_SelectedElement.layout.ToString());
            EditorGUILayout.LabelField("World Bound", m_SelectedElement.worldBound.ToString());
            EditorGUILayout.LabelField("World Clip", m_SelectedElement.worldClip.ToString());
            EditorGUILayout.LabelField("Bounding Box", m_SelectedElement.boundingBox.ToString());

            if (m_ClassList == null)
            {
                InitClassList();
            }
            m_ClassList.DoLayoutList();

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            m_DetailFilter = EditorGUILayout.ToolbarSearchField(m_DetailFilter);
            m_ShowAll      = GUILayout.Toggle(m_ShowAll, Styles.showAllContent, EditorStyles.toolbarButton);
            m_Sort         = GUILayout.Toggle(m_Sort, Styles.sortContent, EditorStyles.toolbarButton);
            GUILayout.EndHorizontal();

            var customProperties = m_SelectedElement.specifiedStyle.m_CustomProperties;

            if (customProperties != null && customProperties.Any())
            {
                foreach (KeyValuePair <string, CustomPropertyHandle> customProperty in customProperties)
                {
                    foreach (StyleValueHandle handle in customProperty.Value.handles)
                    {
                        EditorGUILayout.LabelField(customProperty.Key, customProperty.Value.data.ReadAsString(handle));
                    }
                }
            }

            foreach (PropertyInfo field in m_Sort ? k_SortedFieldInfos : k_FieldInfos)
            {
                if (!string.IsNullOrEmpty(m_DetailFilter) &&
                    field.Name.IndexOf(m_DetailFilter, StringComparison.InvariantCultureIgnoreCase) == -1)
                {
                    continue;
                }

                object val = field.GetValue(m_SelectedElement.computedStyle, null);
                EditorGUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                int specificity;

                if (val is StyleFloat)
                {
                    StyleFloat style = (StyleFloat)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        style.specificity = Int32.MaxValue;
                        style.value       = EditorGUILayout.FloatField(field.Name, ((StyleFloat)val).value);
                        val = style;
                    }
                }
                else if (val is StyleInt)
                {
                    StyleInt style = (StyleInt)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        style.specificity = Int32.MaxValue;
                        style.value       = EditorGUILayout.IntField(field.Name, ((StyleInt)val).value);
                        val = style;
                    }
                }
                else if (val is StyleLength)
                {
                    StyleLength style = (StyleLength)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        style.specificity = Int32.MaxValue;
                        style.value       = EditorGUILayout.FloatField(field.Name, ((StyleLength)val).value.value);
                        val = style;
                    }
                }
                else if (val is StyleColor)
                {
                    StyleColor style = (StyleColor)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        style.specificity = Int32.MaxValue;
                        style.value       = EditorGUILayout.ColorField(field.Name, ((StyleColor)val).value);
                        val = style;
                    }
                }
                else if (val is StyleFont)
                {
                    specificity = HandleReferenceProperty <Font>(field, ref val);
                }
                else if (val is StyleBackground)
                {
                    StyleBackground style = (StyleBackground)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        style.specificity = Int32.MaxValue;
                        Texture2D t = EditorGUILayout.ObjectField(field.Name, style.value.texture, typeof(Texture2D), false) as Texture2D;
                        style.value = new Background(t);
                        val         = style;
                    }
                }
                else if (val is StyleCursor)
                {
                    StyleCursor style = (StyleCursor)val;
                    specificity = style.specificity;
                    if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                    {
                        if (style.value.texture != null)
                        {
                            style.specificity = Int32.MaxValue;
                            var texture = EditorGUILayout.ObjectField(field.Name + "'s texture2D", style.value.texture, typeof(Texture2D), false) as Texture2D;
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            EditorGUIUtility.wideMode = true;
                            var hotspot = EditorGUILayout.Vector2Field(field.Name + "'s hotspot", style.value.hotspot);

                            style.value = new Cursor()
                            {
                                texture = texture, hotspot = hotspot
                            };
                            val = style;
                        }
                        else
                        {
                            int  mouseId      = style.value.defaultCursorId;
                            Enum newEnumValue = EditorGUILayout.EnumPopup(field.Name, (MouseCursor)mouseId);

                            int toCompare = Convert.ToInt32(newEnumValue);
                            if (!Equals(mouseId, toCompare))
                            {
                                style.specificity = Int32.MaxValue;
                                style.value       = new Cursor()
                                {
                                    defaultCursorId = toCompare
                                };
                                val = style;
                            }
                        }
                    }
                }
                else
                {
                    Type type = val.GetType();
                    if (type.IsGenericType && type.GetGenericArguments()[0].IsEnum)
                    {
                        specificity = (int)type.GetProperty("specificity", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val, null);
                        if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                        {
                            var  propInfo     = type.GetProperty("value");
                            Enum enumValue    = propInfo.GetValue(val, null) as Enum;
                            Enum newEnumValue = EditorGUILayout.EnumPopup(field.Name, enumValue);
                            if (!Equals(enumValue, newEnumValue))
                            {
                                propInfo.SetValue(val, newEnumValue, null);
                            }
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField(field.Name, val == null ? "null" : val.ToString());
                        specificity = StyleValueExtensions.UndefinedSpecificity;
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    string propertyName = field.Name;
                    var    inlineStyle  = typeof(IStyle).GetProperty(propertyName);
                    inlineStyle.SetValue(m_SelectedElement.style, val, null);
                }

                if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity)
                {
                    string specificityString = "";
                    switch (specificity)
                    {
                    case StyleValueExtensions.UnitySpecificity:
                        specificityString = "unity stylesheet";
                        break;

                    case StyleValueExtensions.InlineSpecificity:
                        specificityString = "inline";
                        break;

                    case StyleValueExtensions.UndefinedSpecificity:
                        break;

                    default:
                        specificityString = specificity.ToString();
                        break;
                    }
                    GUILayout.Label(specificityString, GUILayout.MinWidth(200), GUILayout.ExpandWidth(false));
                }

                EditorGUILayout.EndHorizontal();
            }
        }
        private static bool CompileFlexShorthand(StylePropertyReader reader, out StyleFloat grow, out StyleFloat shrink, out StyleLength basis)
        {
            grow   = 0f;
            shrink = 1f;
            basis  = StyleKeyword.Auto;
            bool flag       = false;
            int  valueCount = reader.valueCount;
            bool flag2      = valueCount == 1 && reader.IsValueType(0, StyleValueType.Keyword);

            if (flag2)
            {
                bool flag3 = reader.IsKeyword(0, StyleValueKeyword.None);
                if (flag3)
                {
                    flag   = true;
                    grow   = 0f;
                    shrink = 0f;
                    basis  = StyleKeyword.Auto;
                }
                else
                {
                    bool flag4 = reader.IsKeyword(0, StyleValueKeyword.Auto);
                    if (flag4)
                    {
                        flag   = true;
                        grow   = 1f;
                        shrink = 1f;
                        basis  = StyleKeyword.Auto;
                    }
                }
            }
            else
            {
                bool flag5 = valueCount <= 3;
                if (flag5)
                {
                    flag   = true;
                    grow   = 0f;
                    shrink = 1f;
                    basis  = Length.Percent(0f);
                    bool flag6 = false;
                    bool flag7 = false;
                    int  num   = 0;
                    while (num < valueCount & flag)
                    {
                        StyleValueType valueType = reader.GetValueType(num);
                        bool           flag8     = valueType == StyleValueType.Dimension || valueType == StyleValueType.Keyword;
                        if (flag8)
                        {
                            bool flag9 = flag7;
                            if (flag9)
                            {
                                flag = false;
                                break;
                            }
                            flag7 = true;
                            bool flag10 = valueType == StyleValueType.Keyword;
                            if (flag10)
                            {
                                bool flag11 = reader.IsKeyword(num, StyleValueKeyword.Auto);
                                if (flag11)
                                {
                                    basis = StyleKeyword.Auto;
                                }
                            }
                            else
                            {
                                bool flag12 = valueType == StyleValueType.Dimension;
                                if (flag12)
                                {
                                    basis = reader.ReadStyleLength(num);
                                }
                            }
                            bool flag13 = flag6 && num != valueCount - 1;
                            if (flag13)
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            bool flag14 = valueType == StyleValueType.Float;
                            if (flag14)
                            {
                                StyleFloat styleFloat = reader.ReadStyleFloat(num);
                                bool       flag15     = !flag6;
                                if (flag15)
                                {
                                    flag6 = true;
                                    grow  = styleFloat;
                                }
                                else
                                {
                                    shrink = styleFloat;
                                }
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                        num++;
                    }
                }
            }
            return(flag);
        }
        private static bool CompileFlexShorthand(StyleSheet sheet, StyleValueHandle[] handles, int specificity, out StyleFloat grow, out StyleFloat shrink, out StyleLength basis)
        {
            grow   = 0f;
            shrink = 0f;
            basis  = StyleKeyword.Auto;

            bool valid = false;

            if (handles.Length == 1 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.Unset)
            {
                valid  = true;
                grow   = 0f;
                shrink = 1f;
                basis  = StyleKeyword.Auto;
            }
            else if (handles.Length == 1 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.None)
            {
                valid  = true;
                grow   = 0f;
                shrink = 0f;
                basis  = StyleKeyword.Auto;
            }
            else if (handles.Length <= 3 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.Auto)
            {
                valid  = true;
                basis  = StyleKeyword.Auto;
                grow   = 1f;
                shrink = 1f;

                if (handles.Length > 1)
                {
                    grow = sheet.ReadFloat(handles[1]);
                    if (handles.Length > 2)
                    {
                        shrink = sheet.ReadFloat(handles[2]);
                    }
                }
            }
            else if (handles.Length <= 3 && handles[0].valueType == StyleValueType.Float)
            {
                valid = true;

                // TODO: when support for units is implemented, basis must have units, grow and shrink are unitless.
                // This will remove ambiguities. For now we assume (when all values are number)
                //
                // flex: grow               (could be flex: basis)
                // flex: grow shrink        (could be flex: basis grow; or flex: grow basis)
                // flex: grow shrink basis  (could be flex: basis grow shrink)

                grow   = sheet.ReadFloat(handles[0]);
                shrink = 1f;
                basis  = 0f;

                if (handles.Length > 1)
                {
                    if (handles[1].valueType == StyleValueType.Float)
                    {
                        shrink = sheet.ReadFloat(handles[1]);

                        if (handles.Length > 2)
                        {
                            basis = sheet.ReadStyleLength(handles[2], specificity);
                        }
                    }
                    else if (handles[1].valueType == StyleValueType.Keyword && handles[1].valueIndex == (int)StyleValueKeyword.Auto)
                    {
                        basis = StyleKeyword.Auto;
                    }
                }
            }

            grow.specificity   = specificity;
            shrink.specificity = specificity;
            basis.specificity  = specificity;
            return(valid);
        }
示例#14
0
        private static bool CompileFlexShorthand(StylePropertyReader reader, out StyleFloat grow, out StyleFloat shrink, out StyleLength basis)
        {
            grow   = 0f;
            shrink = 1f;
            basis  = StyleKeyword.Auto;

            bool valid      = false;
            var  valueCount = reader.valueCount;

            if (valueCount == 1 && reader.IsValueType(0, StyleValueType.Keyword))
            {
                // Handle none | auto
                if (reader.IsKeyword(0, StyleValueKeyword.None))
                {
                    valid  = true;
                    grow   = 0f;
                    shrink = 0f;
                    basis  = StyleKeyword.Auto;
                }
                else if (reader.IsKeyword(0, StyleValueKeyword.Auto))
                {
                    valid  = true;
                    grow   = 1f;
                    shrink = 1f;
                    basis  = StyleKeyword.Auto;
                }
            }
            else if (valueCount <= 3)
            {
                // Handle [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
                valid = true;

                grow   = 0f;
                shrink = 1f;
                basis  = Length.Percent(0);

                bool growFound  = false;
                bool basisFound = false;
                for (int i = 0; i < valueCount && valid; i++)
                {
                    var valueType = reader.GetValueType(i);
                    if (valueType == StyleValueType.Dimension || valueType == StyleValueType.Keyword)
                    {
                        // Basis
                        if (basisFound)
                        {
                            valid = false;
                            break;
                        }

                        basisFound = true;
                        if (valueType == StyleValueType.Keyword)
                        {
                            if (reader.IsKeyword(i, StyleValueKeyword.Auto))
                            {
                                basis = StyleKeyword.Auto;
                            }
                        }
                        else if (valueType == StyleValueType.Dimension)
                        {
                            basis = reader.ReadStyleLength(i);
                        }

                        if (growFound && i != valueCount - 1)
                        {
                            // If grow is already processed basis must be the last value
                            valid = false;
                        }
                    }
                    else if (valueType == StyleValueType.Float)
                    {
                        var value = reader.ReadStyleFloat(i);
                        if (!growFound)
                        {
                            growFound = true;
                            grow      = value;
                        }
                        else
                        {
                            shrink = value;
                        }
                    }
                    else
                    {
                        valid = false;
                    }
                }
            }

            return(valid);
        }
 public void ApplyFloat(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleFloat property)
 {
     property.Apply(new StyleFloat(currentStyleValue.number, currentStyleValue.keyword)
     {
         specificity = specificity
     }, StylePropertyApplyMode.Copy);
 }
示例#16
0
 public virtual void ChangeValue(StyleFloat value)
 {
     withvalue = true;
 }
示例#17
0
 public override void ChangeValue(StyleFloat val)
 {
     Value = val;
     base.ChangeValue(value);
 }