Exemplo n.º 1
0
        void RefreshMatchingSelectorsContainer()
        {
            m_MatchingSelectorsFoldout.Clear();
            if (BuilderSharedStyles.IsSelectorElement(currentVisualElement))
            {
                return;
            }

            VisualElement matchingSelectors = GeneratedMatchingSelectors();

            if (matchingSelectors != null)
            {
                m_MatchingSelectorsFoldout.Add(matchingSelectors);

                // Forward focus to the panel header.
                matchingSelectors
                .Query()
                .Where(e => e.focusable)
                .ForEach((e) => m_Inspector.AddFocusable(e));
            }
            else
            {
                var label = new Label("None");
                label.AddToClassList(BuilderConstants.InspectorEmptyFoldoutLabelClassName);
                m_MatchingSelectorsFoldout.Add(label);
            }
        }
Exemplo n.º 2
0
        public void Refresh()
        {
            m_AttributesSection.Clear();

            if (currentVisualElement == null)
            {
                return;
            }

            m_AttributesSection.text = currentVisualElement.typeName;

            if (m_Selection.selectionType != BuilderSelectionType.Element &&
                m_Selection.selectionType != BuilderSelectionType.ElementInTemplateInstance &&
                m_Selection.selectionType != BuilderSelectionType.ElementInControlInstance)
            {
                return;
            }

            if (m_Selection.selectionType == BuilderSelectionType.ElementInTemplateInstance && string.IsNullOrEmpty(currentVisualElement.name))
            {
                var helpBox = new HelpBox();
                helpBox.AddToClassList(BuilderConstants.InspectorClassHelpBox);
                helpBox.text = BuilderConstants.NoNameElementAttributes;

                m_AttributesSection.Add(helpBox);
            }

            GenerateAttributeFields();

            // Forward focus to the panel header.
            m_AttributesSection
            .Query()
            .Where(e => e.focusable)
            .ForEach((e) => m_Inspector.AddFocusable(e));
        }
        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);
        }
        void GenerateAttributeFields()
        {
            var attributeList = currentVisualElement.GetAttributeDescriptions();

            foreach (var attribute in attributeList)
            {
                if (attribute == null || attribute.name == null)
                {
                    continue;
                }

                var styleRow = CreateAttributeRow(attribute);
                m_AttributesSection.Add(styleRow);
            }
        }
        void AdjustSpace(PersistedFoldout foldout)
        {
            if (foldout.contentContainer.style.display == DisplayStyle.None)
            {
                return;
            }

            foreach (var dummy in m_DummyItems)
            {
                if (dummy.parent == foldout)
                {
                    dummy.RemoveFromHierarchy();
                }
            }

            var plainViewItem     = foldout.contentContainer.Q <LibraryPlainViewItem>();
            var plainViewItemSize = new Vector2(plainViewItem.resolvedStyle.width, plainViewItem.resolvedStyle.height);
            var itemsInRow        = (int)Mathf.Floor(foldout.contentContainer.resolvedStyle.width / plainViewItemSize.x);

            var foldoutItemsCount = foldout.contentContainer.childCount;

            if (foldoutItemsCount <= itemsInRow)
            {
                foldout.contentContainer.style.justifyContent = Justify.FlexStart;
                return;
            }

            foldout.contentContainer.style.justifyContent = Justify.SpaceAround;
            var rem = foldoutItemsCount % itemsInRow;

            if (rem == 0)
            {
                return;
            }

            var numberOfRequiredDummies = itemsInRow - rem;

            for (var i = 0; i < numberOfRequiredDummies; i++)
            {
                foldout.Add(GetDummyItemView());
            }
        }