VisualElement GeneratedMatchingSelectors()
        {
            m_MatchingSelectors.GetElementMatchers();
            if (m_MatchingSelectors.matchedRulesExtractor.selectedElementRules == null ||
                m_MatchingSelectors.matchedRulesExtractor.selectedElementRules.Count <= 0)
            {
                return(null);
            }

            var container = new VisualElement();

            int ruleIndex = 0;
            var options   = new UssExportOptions();
            var sb        = new StringBuilder();

            foreach (var rule in m_MatchingSelectors.matchedRulesExtractor.selectedElementRules)
            {
                var selectorStr = StyleSheetToUss.ToUssSelector(rule.matchRecord.complexSelector);

                StyleProperty[] props       = rule.matchRecord.complexSelector.rule.properties;
                var             ruleFoldout = new PersistedFoldout()
                {
                    value       = false,
                    text        = selectorStr,
                    viewDataKey = "builder-inspector-rule-foldout__" + ruleIndex
                };
                ruleIndex++;
                container.Add(ruleFoldout);

                if (props.Length == 0)
                {
                    var label = new Label("None");
                    label.AddToClassList(BuilderConstants.InspectorEmptyFoldoutLabelClassName);
                    ruleFoldout.Add(label);
                    continue;
                }

                for (int j = 0; j < props.Length; j++)
                {
                    sb.Clear();
                    StyleSheetToUss.ToUssString(rule.matchRecord.sheet, options, props[j], sb);
                    string s = sb.ToString();

                    s = s?.ToLower();
                    var textField = new TextField(props[j].name)
                    {
                        value = s
                    };
                    textField.isReadOnly = true;
                    ruleFoldout.Add(textField);
                }
            }

            return(container);
        }
Пример #2
0
        public void RefreshUI()
        {
            // On the first RefreshUI, if an element is already selected, we need to make sure it
            // has a valid style. If not, we need to delay our UI building until it is properly initialized.
            if (currentVisualElement != null && float.IsNaN(currentVisualElement.layout.width))
            {
                currentVisualElement.RegisterCallback <GeometryChangedEvent>(RefreshAfterFirstInit);
                return;
            }

            // Determine what to show based on selection.
            ResetSections();
            switch (m_Selection.selectionType)
            {
            case BuilderSelectionType.Nothing:
                EnableSections(Section.NothingSelected);
                return;

            case BuilderSelectionType.StyleSheet:
                EnableSections(Section.StyleSheet);
                return;

            case BuilderSelectionType.StyleSelector:
                EnableSections(
                    Section.StyleSelector |
                    Section.LocalStyles);
                break;

            case BuilderSelectionType.ElementInTemplateInstance:
            case BuilderSelectionType.Element:
                EnableSections(
                    Section.ElementAttributes |
                    Section.ElementInheritedStyles |
                    Section.LocalStyles);
                break;

            case BuilderSelectionType.VisualTreeAsset:
                EnableSections(Section.VisualTreeAsset);
                return;
            }
            if (m_Selection.selectionType == BuilderSelectionType.ElementInTemplateInstance)
            {
                DisableFields();
            }

            // Bind the style selector controls.
            m_SelectorSection.Refresh();

            // Recreate Attribute Fields
            m_AttributesSection.Refresh();

            // Reset current style rule.
            currentRule = null;

            // Get all shared style selectors and draw their fields.
            m_MatchingSelectors.GetElementMatchers();
            m_InheritedStyleSection.Refresh();

            // Create the fields for the overridable styles.
            m_LocalStylesSection.Refresh();
        }
Пример #3
0
        public void RefreshUI()
        {
            // On the first RefreshUI, if an element is already selected, we need to make sure it
            // has a valid style. If not, we need to delay our UI building until it is properly initialized.
            if (currentVisualElement != null &&
                // TODO: This is just for tests to pass. When adding selectors via the fake events
                // we sometimes get selector elements that have no layout and will not layout
                // no matter how many yields we add. They do have the correct panel.
                m_Selection.selectionType != BuilderSelectionType.StyleSelector &&
                float.IsNaN(currentVisualElement.layout.width))
            {
                currentVisualElement.RegisterCallback <GeometryChangedEvent>(RefreshAfterFirstInit);
                return;
            }

            // Determine what to show based on selection.
            ResetSections();
            if (m_Selection.selectionCount > 1)
            {
                EnableSections(Section.MultiSelection);
                return;
            }
            switch (m_Selection.selectionType)
            {
            case BuilderSelectionType.Nothing:
                EnableSections(Section.NothingSelected);
                return;

            case BuilderSelectionType.StyleSheet:
                EnableSections(Section.StyleSheet);
                return;

            case BuilderSelectionType.StyleSelector:
                EnableSections(
                    Section.StyleSelector |
                    Section.LocalStyles);
                break;

            case BuilderSelectionType.ElementInTemplateInstance:
            case BuilderSelectionType.Element:
                EnableSections(
                    Section.ElementAttributes |
                    Section.ElementInheritedStyles |
                    Section.LocalStyles);
                break;

            case BuilderSelectionType.VisualTreeAsset:
                EnableSections(Section.VisualTreeAsset);
                m_CanvasSection.Refresh();
                return;
            }
            if (m_Selection.selectionType == BuilderSelectionType.ElementInTemplateInstance)
            {
                DisableFields();
            }

            // Bind the style selector controls.
            m_SelectorSection.Refresh();

            // Recreate Attribute Fields
            m_AttributesSection.Refresh();

            // Reset current style rule.
            currentRule = null;

            // Get all shared style selectors and draw their fields.
            m_MatchingSelectors.GetElementMatchers();
            m_InheritedStyleSection.Refresh();

            // Create the fields for the overridable styles.
            m_LocalStylesSection.Refresh();

            m_CanvasSection.Refresh();
        }