void VerticalTextAlignOnToggle()
        {
            var result = TextAnchor.UpperLeft;

            switch (m_Target.resolvedStyle.unityTextAlign)
            {
            case TextAnchor.UpperLeft: result = TextAnchor.MiddleLeft; break;

            case TextAnchor.UpperCenter: result = TextAnchor.MiddleCenter; break;

            case TextAnchor.UpperRight: result = TextAnchor.MiddleRight; break;

            case TextAnchor.MiddleLeft: result = TextAnchor.LowerLeft; break;

            case TextAnchor.MiddleCenter: result = TextAnchor.LowerCenter; break;

            case TextAnchor.MiddleRight: result = TextAnchor.LowerRight; break;

            case TextAnchor.LowerLeft: result = TextAnchor.UpperLeft; break;

            case TextAnchor.LowerCenter: result = TextAnchor.UpperCenter; break;

            case TextAnchor.LowerRight: result = TextAnchor.UpperRight; break;
            }
            VerticalTextAlignUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_TextAlignName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_TextAlignName
            });
        }
Example #2
0
        protected void SetStyleSheetValue(string styleName, float value)
        {
            // Remove temporary min-size element.
            m_Target.RemoveMinSizeSpecialElement();

            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, styleName, value);
        }
        public static VisualElement CreateAbsoluteIsland(BuilderPaneWindow paneWindow, VisualElement documentRootElement, Vector2 localMousePosition)
        {
            var vta       = paneWindow.document.visualTreeAsset;
            var selection = paneWindow.primarySelection;

            // Create absolute island container.
            var absoluteIslandContainer = new VisualElement();

            absoluteIslandContainer.name = "unity-absolute-island";
            documentRootElement.Add(absoluteIslandContainer);
            BuilderAssetUtilities.AddElementToAsset(paneWindow.document, absoluteIslandContainer);

            bool isTop    = localMousePosition.y < documentRootElement.resolvedStyle.height / 2;
            bool isBottom = !isTop;
            bool isLeft   = localMousePosition.x < documentRootElement.resolvedStyle.width / 2;
            bool isRight  = !isLeft;

            // Set Absolute position.
            BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "position", Position.Absolute);

            if (isTop && isLeft)
            {
                var left = localMousePosition.x;
                var top  = localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "left", left);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "top", top);
            }
            else if (isTop && isRight)
            {
                var right = documentRootElement.resolvedStyle.width - localMousePosition.x;
                var top   = localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "right", right);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "top", top);
            }
            else if (isBottom && isLeft)
            {
                var left   = localMousePosition.x;
                var bottom = documentRootElement.resolvedStyle.height - localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "left", left);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "bottom", bottom);
            }
            else if (isBottom && isRight)
            {
                var right  = documentRootElement.resolvedStyle.width - localMousePosition.x;
                var bottom = documentRootElement.resolvedStyle.height - localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "right", right);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "bottom", bottom);
            }

            // Need to explicitly update inline styles from asset.
            selection.NotifyOfHierarchyChange(null, absoluteIslandContainer, BuilderHierarchyChangeType.InlineStyle | BuilderHierarchyChangeType.FullRefresh);

            return(absoluteIslandContainer);
        }
        void TextWrapOnToggle()
        {
            var result = WhiteSpace.NoWrap;

            switch (m_Target.resolvedStyle.whiteSpace)
            {
            case WhiteSpace.Normal: result = WhiteSpace.NoWrap; break;

            case WhiteSpace.NoWrap: result = WhiteSpace.Normal; break;
            }
            TextWrapUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_TextWrapName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_TextWrapName
            });
        }
        void TextOverflowOnToggle()
        {
            var result = TextOverflow.Clip;

            switch (m_Target.resolvedStyle.textOverflow)
            {
            case TextOverflow.Clip: result = TextOverflow.Ellipsis; break;

            case TextOverflow.Ellipsis: result = TextOverflow.Clip; break;
            }
            TextOverflowUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_TextOverflowName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle | BuilderHierarchyChangeType.FullRefresh);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_TextOverflowName
            });
        }
        void FlexDirectionOnToggle()
        {
            var result = FlexDirection.Column;

            switch (m_Target.resolvedStyle.flexDirection)
            {
            case FlexDirection.Column: result = FlexDirection.ColumnReverse; break;

            case FlexDirection.ColumnReverse: result = FlexDirection.Row; break;

            case FlexDirection.Row: result = FlexDirection.RowReverse; break;

            case FlexDirection.RowReverse: result = FlexDirection.Column; break;
            }
            FlexDirectionUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_FlexDirectionName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_FlexDirectionName
            });
        }
        void JustifyContentOnToggle()
        {
            var result = Justify.FlexStart;

            switch (m_Target.resolvedStyle.justifyContent)
            {
            case Justify.FlexStart: result = Justify.Center; break;

            case Justify.Center: result = Justify.FlexEnd; break;

            case Justify.FlexEnd: result = Justify.SpaceBetween; break;

            case Justify.SpaceBetween: result = Justify.SpaceAround; break;

            case Justify.SpaceAround: result = Justify.FlexStart; break;
            }
            JustifyContentUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_JustifyContentName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_JustifyContentName
            });
        }
        void AlignItemsOnToggle()
        {
            var result = Align.Auto;

            switch (m_Target.resolvedStyle.alignItems)
            {
            case Align.Auto: result = Align.FlexStart; break;

            case Align.FlexStart: result = Align.Center; break;

            case Align.Center: result = Align.FlexEnd; break;

            case Align.FlexEnd: result = Align.Stretch; break;

            case Align.Stretch: result = Align.Auto; break;
            }
            AlignItemsUpdateToggleIcon(result);
            BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_AlignItemsName, result);
            m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle);
            m_Selection.NotifyOfStylingChange(null, new List <string>()
            {
                k_AlignItemsName
            });
        }
Example #9
0
 protected void SetStyleSheetValue(string styleName, float value)
 {
     BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, styleName, Mathf.Round(value));
 }