Exemplo n.º 1
0
 //Only used to avoid allocations in Q<>() Don't use this unless you know what you're doing
 internal UQueryBuilder <T> SingleBaseType()
 {
     parts.Add(StyleSelectorPart.CreatePredicate(UQuery.IsOfType <T> .s_Instance));
     return(this);
 }
Exemplo n.º 2
0
 public UQueryBuilder <T> Where(Func <T, bool> selectorPredicate)
 {
     //we can't use a static instance as in the QueryState<T>.ForEach below since the query might be long lived
     parts.Add(StyleSelectorPart.CreatePredicate(new UQuery.PredicateWrapper <T>(selectorPredicate)));
     return(this);
 }
Exemplo n.º 3
0
        void SetupReferences()
        {
            if (complexSelectors == null || rules == null)
            {
                return;
            }

            // Setup rules and properties for var
            foreach (var rule in rules)
            {
                foreach (var property in rule.properties)
                {
                    if (property.name.StartsWith("--"))
                    {
                        ++rule.customPropertiesCount;
                        property.isCustomProperty = true;
                    }

                    foreach (var handle in property.values)
                    {
                        if (handle.IsVarFunction())
                        {
                            property.requireVariableResolve = true;
                            break;
                        }
                    }
                }
            }

            for (int i = 0, count = complexSelectors.Length; i < count; i++)
            {
                complexSelectors[i].CachePseudoStateMasks();
            }

            orderedClassSelectors = new TableType(StringComparer.Ordinal);
            orderedNameSelectors  = new TableType(StringComparer.Ordinal);
            orderedTypeSelectors  = new TableType(StringComparer.Ordinal);

            for (int i = 0; i < complexSelectors.Length; i++)
            {
                // Here we set-up runtime-only pointers
                StyleComplexSelector complexSel = complexSelectors[i];

                if (complexSel.ruleIndex < rules.Length)
                {
                    complexSel.rule = rules[complexSel.ruleIndex];
                }

                complexSel.orderInStyleSheet = i;

                StyleSelector     lastSelector = complexSel.selectors[complexSel.selectors.Length - 1];
                StyleSelectorPart part         = lastSelector.parts[0];

                string key = part.value;

                TableType tableToUse = null;

                switch (part.type)
                {
                case StyleSelectorType.Class:
                    tableToUse = orderedClassSelectors;
                    break;

                case StyleSelectorType.ID:
                    tableToUse = orderedNameSelectors;
                    break;

                case StyleSelectorType.Type:
                case StyleSelectorType.Wildcard:
                    key        = part.value ?? "*";
                    tableToUse = orderedTypeSelectors;
                    break;

                // in this case we assume a wildcard selector
                // since a selector such as ":selected" applies to all elements
                case StyleSelectorType.PseudoClass:
                    key        = "*";
                    tableToUse = orderedTypeSelectors;
                    break;

                default:
                    Debug.LogError($"Invalid first part type {part.type}");
                    break;
                }

                if (tableToUse != null)
                {
                    StyleComplexSelector previous;
                    if (tableToUse.TryGetValue(key, out previous))
                    {
                        complexSel.nextInTable = previous;
                    }
                    tableToUse[key] = complexSel;
                }
            }
        }