Exemplo n.º 1
0
        void SetAnchorHandleState(TrackedStyle style, bool state)
        {
            string anchorName = string.Empty;

            switch (style)
            {
            case TrackedStyle.Top: anchorName = "top-anchor"; break;

            case TrackedStyle.Left: anchorName = "left-anchor"; break;

            case TrackedStyle.Bottom: anchorName = "bottom-anchor"; break;

            case TrackedStyle.Right: anchorName = "right-anchor"; break;

            default: return;
            }

            if (state)
            {
                m_HandleElements[anchorName].AddToClassList(s_ActiveAnchorClassName);
            }
            else
            {
                m_HandleElements[anchorName].RemoveFromClassList(s_ActiveAnchorClassName);
            }
        }
Exemplo n.º 2
0
        void OnAnchorClick(TrackedStyle primaryStyle, TrackedStyle oppositeStyle, TrackedStyle lengthStyle)
        {
            var primaryIsUnset = IsNoneOrAuto(primaryStyle);   // We can enable primary.
            var oppositeIsSet  = !IsNoneOrAuto(oppositeStyle); // We can safely unset primary.

            if (!primaryIsUnset && !oppositeIsSet)             // Nothing to do.
            {
                return;
            }

            var parentLength         = GetResolvedStyleFloat(lengthStyle, m_Target.parent);
            var parentBorderPrimary  = GetBorderResolvedStyleFloat(primaryStyle, m_Target.parent);
            var parentBorderOpposite = GetBorderResolvedStyleFloat(oppositeStyle, m_Target.parent);

            var primary  = GetStyleSheetFloat(primaryStyle);
            var opposite = GetStyleSheetFloat(oppositeStyle);
            var length   = GetStyleSheetFloat(lengthStyle);

            var primaryName = GetStyleName(primaryStyle);
            var lengthName  = GetStyleName(lengthStyle);

            var marginPrimary   = GetMargineResolvedStyleFloat(primaryStyle);
            var marginOpposite  = GetMargineResolvedStyleFloat(oppositeStyle);
            var totalAxisMargin = marginPrimary + marginOpposite;

            var changeList = new List <string>()
            {
                primaryName, lengthName
            };

            if (primaryIsUnset)
            {
                var newPrimaryValue = parentLength - opposite - length - totalAxisMargin - parentBorderOpposite - parentBorderPrimary;
                SetStyleSheetValue(primaryName, newPrimaryValue);
                RemoveStyleSheetValue(lengthName);

                SetAnchorHandleState(primaryStyle, true);

                m_Selection.NotifyOfStylingChange(this, changeList);
                m_Selection.NotifyOfHierarchyChange(this, m_Target, BuilderHierarchyChangeType.InlineStyle);
            }
            else if (oppositeIsSet)
            {
                var newLengthValue = parentLength - opposite - primary - totalAxisMargin - parentBorderOpposite - parentBorderPrimary;
                SetStyleSheetValue(lengthName, newLengthValue);
                RemoveStyleSheetValue(primaryName);

                SetAnchorHandleState(primaryStyle, false);

                m_Selection.NotifyOfStylingChange(this, changeList);
                m_Selection.NotifyOfHierarchyChange(this, m_Target, BuilderHierarchyChangeType.InlineStyle);
            }
        }
Exemplo n.º 3
0
        ///

        protected float GetStyleSheetFloat(TrackedStyle trackedStyle)
        {
            var name = GetStyleName(trackedStyle);

            if (IsNoneOrAuto(trackedStyle))
            {
                return(GetResolvedStyleFloat(trackedStyle, m_Target));
            }
            else
            {
                return(GetStyleSheetFloat(name));
            }
        }
Exemplo n.º 4
0
        void OnDrag(
            TrackedStyle primaryStyle,
            float onStartDragLength,
            float onStartDragPrimary,
            float delta,
            List <string> changeList)
        {
            var oppositeStyle = GetOppositeStyle(primaryStyle);
            var lengthStyle   = GetLengthStyle(primaryStyle);

            // Make sure our delta is a whole number so we don't end up with non-whole pixel values.
            delta = Mathf.Ceil(delta / canvas.zoomScale);

            if (!IsNoneOrAuto(oppositeStyle) && !IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                changeList.Add(GetStyleName(primaryStyle));
            }
            else if (IsNoneOrAuto(oppositeStyle) && !IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                changeList.Add(GetStyleName(primaryStyle));
                changeList.Add(GetStyleName(lengthStyle));
            }
            else if (!IsNoneOrAuto(oppositeStyle) && IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                changeList.Add(GetStyleName(lengthStyle));
            }
            else
            {
                if (primaryStyle == TrackedStyle.Top || primaryStyle == TrackedStyle.Left)
                {
                    SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                    SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                    changeList.Add(GetStyleName(primaryStyle));
                    changeList.Add(GetStyleName(lengthStyle));
                }
                else
                {
                    SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                    changeList.Add(GetStyleName(lengthStyle));
                }
            }
        }
Exemplo n.º 5
0
        void OnMove(
            TrackedStyle trackedStyle,
            bool force,
            float onStartDragPrimary,
            float delta,
            List <string> changeList)
        {
            if (IsNoneOrAuto(trackedStyle) && !force)
            {
                return;
            }

            var styleName = GetStyleName(trackedStyle);

            SetStyleSheetValue(styleName, onStartDragPrimary + delta);
            m_ScratchChangeList.Add(styleName);
        }
Exemplo n.º 6
0
        void OnDrag(
            TrackedStyle primaryStyle,
            float onStartDragLength,
            float onStartDragPrimary,
            float delta,
            List <string> changeList)
        {
            var oppositeStyle = GetOppositeStyle(primaryStyle);
            var lengthStyle   = GetLengthStyle(primaryStyle);

            delta /= canvas.zoomScale;

            if (!IsNoneOrAuto(oppositeStyle) && !IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                changeList.Add(GetStyleName(primaryStyle));
            }
            else if (IsNoneOrAuto(oppositeStyle) && !IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                changeList.Add(GetStyleName(primaryStyle));
                changeList.Add(GetStyleName(lengthStyle));
            }
            else if (!IsNoneOrAuto(oppositeStyle) && IsNoneOrAuto(primaryStyle))
            {
                SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                changeList.Add(GetStyleName(lengthStyle));
            }
            else
            {
                if (primaryStyle == TrackedStyle.Top || primaryStyle == TrackedStyle.Left)
                {
                    SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                    SetStyleSheetValue(primaryStyle, onStartDragPrimary - delta);
                    changeList.Add(GetStyleName(primaryStyle));
                    changeList.Add(GetStyleName(lengthStyle));
                }
                else
                {
                    SetStyleSheetValue(lengthStyle, onStartDragLength + delta);
                    changeList.Add(GetStyleName(lengthStyle));
                }
            }
        }
Exemplo n.º 7
0
        ///

        protected string GetStyleName(TrackedStyle trackedStyle)
        {
            switch (trackedStyle)
            {
            case TrackedStyle.Width: return(s_WidthStyleName);

            case TrackedStyle.Height: return(s_HeightStyleName);

            case TrackedStyle.Left: return(s_LeftStyleName);

            case TrackedStyle.Top: return(s_TopStyleName);

            case TrackedStyle.Right: return(s_RightStyleName);

            case TrackedStyle.Bottom: return(s_BottomStyleName);
            }
            return(null);
        }
Exemplo n.º 8
0
        protected TrackedStyle GetLengthStyle(TrackedStyle trackedStyle)
        {
            switch (trackedStyle)
            {
            case TrackedStyle.Width: return(TrackedStyle.Width);

            case TrackedStyle.Height: return(TrackedStyle.Height);

            case TrackedStyle.Left: return(TrackedStyle.Width);

            case TrackedStyle.Top: return(TrackedStyle.Height);

            case TrackedStyle.Right: return(TrackedStyle.Width);

            case TrackedStyle.Bottom: return(TrackedStyle.Height);
            }

            throw new Exception("Invalid tracked style.");
        }
Exemplo n.º 9
0
        protected float GetBorderResolvedStyleFloat(TrackedStyle trackedStyle, VisualElement target)
        {
            if (target == null)
            {
                return(0);
            }

            switch (trackedStyle)
            {
            case TrackedStyle.Left: return(target.resolvedStyle.borderLeftWidth);

            case TrackedStyle.Top: return(target.resolvedStyle.borderTopWidth);

            case TrackedStyle.Right: return(target.resolvedStyle.borderRightWidth);

            case TrackedStyle.Bottom: return(target.resolvedStyle.borderBottomWidth);
            }

            return(0);
        }
Exemplo n.º 10
0
        void OnMove(
            TrackedStyle trackedStyle,
            bool force,
            float onStartDragPrimary,
            float delta,
            List <string> changeList)
        {
            if (IsNoneOrAuto(trackedStyle) && !force)
            {
                return;
            }

            // Make sure our delta is a whole number so we don't end up with non-whole pixel values.
            delta = Mathf.Ceil(delta / canvas.zoomScale);

            var styleName = GetStyleName(trackedStyle);

            SetStyleSheetValue(styleName, onStartDragPrimary + delta);
            m_ScratchChangeList.Add(styleName);
        }
Exemplo n.º 11
0
        protected float GetMargineResolvedStyleFloat(TrackedStyle trackedStyle)
        {
            var target = m_Target;

            if (target == null)
            {
                return(0);
            }

            switch (trackedStyle)
            {
            case TrackedStyle.Left: return(target.resolvedStyle.marginLeft);

            case TrackedStyle.Top: return(target.resolvedStyle.marginTop);

            case TrackedStyle.Right: return(target.resolvedStyle.marginRight);

            case TrackedStyle.Bottom: return(target.resolvedStyle.marginBottom);
            }

            return(0);
        }
Exemplo n.º 12
0
        protected float GetResolvedStyleFloat(TrackedStyle trackedStyle, VisualElement target)
        {
            if (target == null)
            {
                return(0);
            }

            switch (trackedStyle)
            {
            case TrackedStyle.Width: return(target.resolvedStyle.width);

            case TrackedStyle.Height: return(target.resolvedStyle.height);

            case TrackedStyle.Left: return(target.resolvedStyle.left);

            case TrackedStyle.Top: return(target.resolvedStyle.top);

            case TrackedStyle.Right: return(target.resolvedStyle.right);

            case TrackedStyle.Bottom: return(target.resolvedStyle.bottom);
            }
            return(0);
        }
Exemplo n.º 13
0
        protected bool IsNoneOrAuto(TrackedStyle trackedStyle)
        {
            if (m_Target == null)
            {
                return(false);
            }

            switch (trackedStyle)
            {
            case TrackedStyle.Width: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.width));

            case TrackedStyle.Height: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.height));

            case TrackedStyle.Left: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.left));

            case TrackedStyle.Top: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.top));

            case TrackedStyle.Right: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.right));

            case TrackedStyle.Bottom: return(IsComputedStyleNoneOrAuto(m_Target.computedStyle.bottom));
            }

            return(false);
        }
Exemplo n.º 14
0
        protected bool IsNoneOrAuto(TrackedStyle trackedStyle)
        {
            if (m_Target == null)
            {
                return(false);
            }

            switch (trackedStyle)
            {
            case TrackedStyle.Width: return(m_Target.computedStyle.width == StyleKeyword.None || m_Target.computedStyle.width == StyleKeyword.Auto);

            case TrackedStyle.Height: return(m_Target.computedStyle.height == StyleKeyword.None || m_Target.computedStyle.height == StyleKeyword.Auto);

            case TrackedStyle.Left: return(m_Target.computedStyle.left == StyleKeyword.None || m_Target.computedStyle.left == StyleKeyword.Auto);

            case TrackedStyle.Top: return(m_Target.computedStyle.top == StyleKeyword.None || m_Target.computedStyle.top == StyleKeyword.Auto);

            case TrackedStyle.Right: return(m_Target.computedStyle.right == StyleKeyword.None || m_Target.computedStyle.right == StyleKeyword.Auto);

            case TrackedStyle.Bottom: return(m_Target.computedStyle.bottom == StyleKeyword.None || m_Target.computedStyle.bottom == StyleKeyword.Auto);
            }

            return(false);
        }
Exemplo n.º 15
0
        protected void SetStyleSheetValue(TrackedStyle trackedStyle, float value)
        {
            var name = GetStyleName(trackedStyle);

            SetStyleSheetValue(name, value);
        }
Exemplo n.º 16
0
 protected float GetResolvedStyleValue(TrackedStyle trackedStyle)
 {
     return(GetResolvedStyleFloat(trackedStyle, m_Target));
 }