Exemplo n.º 1
0
 /// <summary>
 /// Overrides the existing values
 /// </summary>
 /// <param name="declaration"></param>
 public void Override(Serialization.StyleDeclaration declaration)
 {
     foreach (StyleProperty property in _styleSheetDeclaration.Properties)
     {
         _cached[property.Name] = property.Value;
     }
 }
Exemplo n.º 2
0
 public bool Equals(StyleDeclaration other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     return(Equals(other.Type, Type) &&
            ArrayUtil <StyleProperty> .Equals(other.Properties, Properties) &&
            ArrayUtil <string> .Equals(other.MediaQueries, MediaQueries));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public object Clone()
        {
            StyleDeclaration clone = new StyleDeclaration
                                         {
                                             Module = Module,
                                             Type = Type,
                                             Class = Class,
                                             Id = Id
                                         };
            if (null != Properties)
                clone.Properties = ArrayUtil<StyleProperty>.Clone(Properties);

            if (null != MediaQueries)
                clone.MediaQueries = ArrayUtil<MediaQuery>.Clone(MediaQueries);

            return clone;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public object Clone()
        {
            StyleDeclaration clone = new StyleDeclaration
            {
                Module = Module,
                Type   = Type,
                Class  = Class,
                Id     = Id
            };

            if (null != Properties)
            {
                clone.Properties = ArrayUtil <StyleProperty> .Clone(Properties);
            }

            if (null != MediaQueries)
            {
                clone.MediaQueries = ArrayUtil <MediaQuery> .Clone(MediaQueries);
            }

            return(clone);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="declaration">Serialized style declaration</param>
 public StyleSheetValuesFactory(Serialization.StyleDeclaration declaration)
 {
     _styleSheetDeclaration = declaration;
 }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position.height = StyleDeclarationInsetRenderer.HeaderHeight;

            SerializedProperty module = property.FindPropertyRelative("Module");

            _insetRenderer.Error = string.IsNullOrEmpty(module.stringValue) ? "Style module not defined" : null;

            SerializedProperty type      = property.FindPropertyRelative("Type");
            SerializedProperty classname = property.FindPropertyRelative("Class");
            SerializedProperty id        = property.FindPropertyRelative("Id");

            var selectorString = StyleSelector.BuildString(type.stringValue, classname.stringValue, id.stringValue);

            var title = selectorString;

            SerializedProperty mediaQueries = property.FindPropertyRelative("MediaQueries");
            int size = mediaQueries.arraySize;

            if (size > 0)
            {
                /*var mkList = new System.Collections.Generic.List<string>();
                 * for (int i = 0; i < size; i++)
                 * {
                 *      var query = mediaQueries.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue;
                 *      mkList.Add(query);
                 * }*/
                //title += string.Format(" @media {0}", string.Join(", ", mkList.ToArray()));
                title += string.Format(" @media");
            }

            var isScanning = EditorSettings.LiveStyling && Application.isPlaying;

            var passed = 0 == size || !isScanning;

            if (!passed)
            {
                // let's assume it will pass
                passed = true;

                // loop thgough each query
                for (int i = 0; i < size; i++)
                {
                    var query = mediaQueries.GetArrayElementAtIndex(i);
                    var name  = query.FindPropertyRelative("Name").stringValue;
                    var value = SerializedPropertyHelper.Read(query); //Debug.Log("value: " + value);
                    passed = MediaQueryManager.Instance.EvaluateQuery(name, value);

                    // when a single query doesn't pass, break the loop
                    if (!passed)
                    {
                        break;
                    }
                }
                //GUI.backgroundColor = mediaQueryPasses ? Color.green : Color.red;
            }

            _insetRenderer.MediaQueriesPassed = passed;

            CurrentType = type.stringValue;

            Rect pos2 = new Rect(position.x, position.y, position.width, property.isExpanded ? GetPropertyHeight(property, label) : position.height);

            /*label = */ EditorGUI.BeginProperty(position, label, property);

            property.isExpanded = _insetRenderer.RenderStart(pos2, title, property.isExpanded);

            EditorGUI.EndProperty();

            if (!property.isExpanded)
            {
                return;
            }

            position.y += StyleDeclarationInsetRenderer.HeaderHeight;

            if (!eDrivenStyleSheetEditor.EditorLocked)
            {
                position.y += ToolbarHeight;
            }

            position.width -= BorderMetrics.Right;

            //EditorGUI.indentLevel += 1;
            position.x += BorderMetrics.Left;

            /**
             * 1. Render media queries
             * */
            var numberOfMediaQueries = RenderMediaQueries(ref position, property);

            /**
             * 2. Render properties
             * */
            var numberOfProperties = RenderProperties(position, property);

            /*if (Event.current.type == EventType.ValidateCommand)
             * {
             *      Debug.Log(Event.current.type);
             * }*/

            /*var isUndo = Event.current.type == EventType.ValidateCommand &&
             *                        Event.current.commandName == "UndoRedoPerformed";*/

            if (GUI.changed /* || isUndo*/)
            {
                eDrivenStyleSheet edss = (eDrivenStyleSheet)property.serializedObject.targetObject;
                StyleSheet        ss   = edss.StyleSheet;

                StyleDeclaration declaration = null;
                foreach (StyleDeclaration dec in ss.Declarations)
                {
                    //Debug.Log(StyleSelector.BuildString(dec.Type, dec.Class, dec.Id));
                    /* Note: this is buggy, think about how to reference it without using the selector */
                    if (StyleSelector.BuildString(dec.Type, dec.Class, dec.Id) == selectorString)
                    {
                        //Debug.Log("Found declaration: " + dec);
                        declaration = dec;
                        break;
                    }
                }

                if (null == declaration)
                {
                    return;                     // nothing found?
                }

                /**
                 * 1. Get old properties
                 * */
                DictionaryDelta propertiesDelta = new DictionaryDelta();
                propertiesDelta.SnapshotBefore(declaration.Properties);

                /**
                 * 2. Apply changes
                 * */
                var propertiesChanged = property.serializedObject.ApplyModifiedProperties();

                /**
                 * 3. Get new properties
                 * */
                propertiesDelta.SnapshotAfter(declaration.Properties);

                /**
                 * 4. Process delta
                 * */
                propertiesDelta.Process();

                /**
                 * 1. Get old media queries
                 * */
                DictionaryDelta mediaQueriesDelta = new DictionaryDelta();
                mediaQueriesDelta.SnapshotBefore(declaration.MediaQueries);

                /**
                 * 2. Apply changes
                 * */
                var mediaQueriesChanged = property.serializedObject.ApplyModifiedProperties();

                /**
                 * 3. Get new properties
                 * */
                mediaQueriesDelta.SnapshotAfter(declaration.MediaQueries);

                /**
                 * 4. Process delta
                 * */
                propertiesDelta.Process();

                var selector = Selector.BuildSelector(type.stringValue, classname.stringValue, id.stringValue);

                var propertyCountChanged   = _oldNumberOfProperties != numberOfProperties;
                var mediaQueryCountChanged = _oldNumberOfMediaQueries != numberOfMediaQueries;

                if (propertiesChanged || mediaQueriesChanged || propertyCountChanged || mediaQueryCountChanged)
                {
                    var moduleId = property.FindPropertyRelative("Module").stringValue;
                    if (string.IsNullOrEmpty(moduleId))
                    {
                        Debug.Log("Module not defined (unknown module ID)");
                    }
                    else
                    {
                        StyleModuleManager.Instance.GetModule(moduleId).UpdateStyles(selector, propertiesDelta);
                    }

                    if (propertyCountChanged)
                    {
                        _oldNumberOfProperties = numberOfProperties;
                    }
                    if (mediaQueryCountChanged)
                    {
                        _oldNumberOfMediaQueries = numberOfMediaQueries;
                    }

                    StyleSheetPropertyDrawer.ShouldProcessStyles = true;
                }

                GUI.changed = false;
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="declaration">Serialized style declaration</param>
 public StyleSheetValuesFactory(Serialization.StyleDeclaration declaration)
 {
     _styleSheetDeclaration = declaration;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Builds the string version of the selector
 /// </summary>
 /// <param name="declaration"></param>
 /// <returns></returns>
 internal static string BuildString(Serialization.StyleDeclaration declaration)
 {
     return(BuildString(declaration.Type, declaration.Class, declaration.Id));
 }
Exemplo n.º 9
0
 public bool Equals(StyleDeclaration other)
 {
     if (ReferenceEquals(null, other)) return false;
     return Equals(other.Type, Type) && 
         ArrayUtil<StyleProperty>.Equals(other.Properties, Properties) &&
         ArrayUtil<string>.Equals(other.MediaQueries, MediaQueries);
 }