Exemplo n.º 1
0
        /// <summary>
        /// Initializes the Singleton instance
        /// </summary>
        internal void Initialize()
        {
            //StyleDeclaration style = StyleManager.Instance.GetStyleDeclaration("global");
            //if (null == style)
            //{
            //    style = new StyleDeclaration();
                
            //    var dict = new Dictionary<string, object> { { "foo", "bar" } };
            //    style.Factory = new StyleTableValuesFactory(dict); // ?? DefaultValues ???????

            //    StyleManager.Instance.SetStyleDeclaration("global", style, false);
            //}

            var styleManager = StyleManager.Instance;
            var selector = new Selector("global", null, null);
            var mergedStyle = styleManager.GetMergedStyleDeclaration("global");
            var style = new StyleDeclaration(selector, mergedStyle == null);

            if (style.Set1 == null)
            {
                //Debug.Log("Creating DefaultValues for " + selector);
                var dict = new StyleTable(); // { { "foo", "bar" } };
                style.Set1 = new StyleTableValuesFactory(dict);
            }

            if (null != mergedStyle && 
                (null == mergedStyle.Set1 ||
                style.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
            {
                styleManager.SetStyleDeclaration(style.SelectorString, style, false);
            }

            //Debug.Log("Global style initialized: " + styleManager.GetStyleDeclaration("global"));
        }
Exemplo n.º 2
0
        ///<summary>
        /// Returns true if the component matches the selector
        ///</summary>
        ///<param name="component"></param>
        ///<param name="selector"></param>
        ///<returns></returns>
        internal bool MatchesSelector(Component component, Selector selector)
        {
            if (null == component)
                throw new Exception("Component is null");

            if (null == selector)
                throw new Exception("Selector is null");

            var type = component.GetType();

            /**
             * 1. Check subject
             * */
            if (type.FullName != selector.Subject)
                return false;

            if (0 == selector.Conditions.Count)
                return true; // nothing more to do

            /**
             * 1. Default adapter
             * */
            _styleClient = _defaultAdapter;

            /**
             * 2. If specified for a component...
             * */
            if (_adapters.ContainsKey(type))
                _styleClient = _adapters[type];

            /**
             * 3. Initialize with component instance
             * */
            _styleClient.Initialize(component);

            /**
             * 4. Check conditions
             * */
            foreach (CSSCondition condition in selector.Conditions)
            {
                if (!condition.MatchesStyleClient(_styleClient))
                    return false;
            }

            return true;
        }
Exemplo n.º 3
0
        public void UpdateStyles(Selector selector, DictionaryDelta delta)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("##### UpdateStyles [{0}] #####", selector));
            }
#endif
            // ReSharper disable once UnusedVariable
            /* Important */
            var connector = StylingOverlayConnector.Instance;

            // process styles - live
            if (EditorSettings.LiveStyling)
                Gui.ProcessStyles();

            if (!Application.isPlaying && ProcessEditModeChanges ||
                Application.isPlaying && ProcessPlayModeChanges)
            {
                Traverser.UpdateStyles(selector, delta);
            }
        }
Exemplo n.º 4
0
 internal Selector(string subject, List<CSSCondition> conditions, Selector ancestor)
 {
     Subject = subject;
     Conditions = conditions;
     Ancestor = ancestor;
 }
Exemplo n.º 5
0
        ///<summary>
        ///</summary>
        ///<param name="type"></param>
        ///<param name="class"></param>
        ///<param name="id"></param>
        ///<param name="pseudo"></param>
        ///<returns></returns>
        internal static Selector BuildSelector(string type, string @class, string id, string pseudo)
        {
            Selector selector = new Selector(null);
            if (!string.IsNullOrEmpty(type))
            {
                selector.Subject = type;
            }
            //Debug.Log(2);

            List<CSSCondition> conditions = new List<CSSCondition>();

            if (!string.IsNullOrEmpty(@class))
            {
                conditions.Add(new CSSCondition(CSSConditionKind.Class, @class));
            }
            //Debug.Log(3);
            if (!string.IsNullOrEmpty(id))
            {
                conditions.Add(new CSSCondition(CSSConditionKind.Id, id));
            }

            /*if (!string.IsNullOrEmpty(pseudo))
            {
                conditions.Add(new CSSCondition(CSSConditionKind.Pseudo, pseudo));
            }*/

            selector.Conditions = conditions;

            return selector;
        }
// ReSharper restore UnassignedField.Global
#endif

        internal static void Load()
        {
            //Debug.Log("##### Loading default styles #####");

            var styleManager = StyleManager.Instance;

            if (null == _styleableClasses)
                _styleableClasses = StyleReflector.GetAllStyleableClasses();
            
#if DEBUG
            if (DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Type type in _styleableClasses)
                {
                    sb.AppendLine(type.FullName);
                }
                Debug.Log(string.Format(@"Default style declarations from styleable types ({0}):
{1}", _styleableClasses.Count, sb));
            }
#endif

#if DEBUG
            if (DebugMode)
            {
                _time = DateTime.Now;
            }
#endif

            foreach (Type type in _styleableClasses)
            {
                //var selector = StyleSelector.FormatType(type.FullName);
                var fullName = type.FullName; // string.Format("[{0}]", type.FullName);
                object selector = new Selector(fullName, null);
                var mergedStyle = styleManager.GetMergedStyleDeclaration(fullName);
                /*if (null != mergedStyle)
                    Debug.Log("mergedStyle for " + type.FullName + " is:" + mergedStyle);*/

                /**
                 * Creating style declaration
                 * */
                var declaration = new StyleDeclaration(selector, mergedStyle == null); // {IsReflected = true};

                if (declaration.Set1 == null)
                {
                    declaration.Set1 = new DefaultValuesFactory(type);
                }

                if (mergedStyle != null &&
                    (null == mergedStyle.Set1 ||
                    //ObjectUtil.compare(new style.defaultFactory(), new mergedStyle.defaultFactory())))
                    declaration.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
                {
                    //Debug.Log("*** Setting for " + style.SelectorString);
                    styleManager.SetStyleDeclaration(declaration.SelectorString, declaration, false);
                }
                //Debug.Log("   -> " + StyleManager.Instance.GetStyleDeclaration(selector));
            }

#if DEBUG
            if (DebugMode)
            {
                var diff = DateTime.Now.Subtract(_time);
                Debug.Log("It took " + diff.TotalMilliseconds + " ms.");
            }
#endif
        }
        private void FindComps(ICollection <Component> components, Transform transform, Selector selector)
        {
            /*if (transform.name == "Test")
             * {
             *  Debug.Log("transform: " + transform);
             * }*/

            var list = new List <Component>();

            var componentsOnTransform = transform.GetComponents <Component>();

            list.AddRange(componentsOnTransform);

            /*var mbsOnTransform = transform.GetComponents<MonoBehaviour>();
             * list.AddRange(mbsOnTransform);*/

            foreach (var component in list)
            {
                if (null == component)
                {
                    continue; // TODO: there is a case when component is null -> investigate!!!
                }

                /**
                 * Note: not equal, but containing
                 * We are looking for components having this selector as a part of theirs
                 * For instance, if selector is "Button", then "Button.miki" should also be processed (but only if not overriden with .miki declaration TODO)
                 * */
                if (StyleClientManager.Instance.MatchesSelector(component, selector))
                {
                    components.Add(component);
                }
            }

            foreach (Transform child in transform.transform)
            {
                FindComps(components, child, selector);
            }
        }