示例#1
0
        void AssignState(GUIStyleState state)
        {
            state.textColor = textColor.GetSpecifiedValueOrDefault(state.textColor);
            if (backgroundImage.value != null)
            {
                state.background = backgroundImage.value;
                if (state.scaledBackgrounds == null || state.scaledBackgrounds.Length < 1 || state.scaledBackgrounds[0] != backgroundImage.value)
                {
                    state.scaledBackgrounds = new Texture2D[1] {
                        backgroundImage.value
                    }
                }
                ;
            }
        }

        void AssignRect(RectOffset rect, ref StyleValue <int> left, ref StyleValue <int> top, ref StyleValue <int> right, ref StyleValue <int> bottom)
        {
            rect.left   = left.GetSpecifiedValueOrDefault(rect.left);
            rect.top    = top.GetSpecifiedValueOrDefault(rect.top);
            rect.right  = right.GetSpecifiedValueOrDefault(rect.right);
            rect.bottom = bottom.GetSpecifiedValueOrDefault(rect.bottom);
        }

        void AssignRect(RectOffset rect, ref StyleValue <float> left, ref StyleValue <float> top, ref StyleValue <float> right, ref StyleValue <float> bottom)
        {
            rect.left   = (int)left.GetSpecifiedValueOrDefault(rect.left);
            rect.top    = (int)top.GetSpecifiedValueOrDefault(rect.top);
            rect.right  = (int)right.GetSpecifiedValueOrDefault(rect.right);
            rect.bottom = (int)bottom.GetSpecifiedValueOrDefault(rect.bottom);
        }
示例#2
0
        public void WriteToGUIStyle(GUIStyle style)
        {
            style.alignment = (TextAnchor)(textAlignment.GetSpecifiedValueOrDefault((int)style.alignment));
            style.wordWrap  = wordWrap.GetSpecifiedValueOrDefault(style.wordWrap);
            style.clipping  = (TextClipping)(textClipping.GetSpecifiedValueOrDefault((int)style.clipping));
            if (font.value != null)
            {
                style.font = font.value;
            }
            style.fontSize  = fontSize.GetSpecifiedValueOrDefault(style.fontSize);
            style.fontStyle = (FontStyle)(fontStyle.GetSpecifiedValueOrDefault((int)style.fontStyle));

            AssignRect(style.margin, ref marginLeft, ref marginTop, ref marginRight, ref marginBottom);
            AssignRect(style.padding, ref paddingLeft, ref paddingTop, ref paddingRight, ref paddingBottom);
            AssignRect(style.border, ref sliceLeft, ref sliceTop, ref sliceRight, ref sliceBottom);
            AssignState(style.normal);
            AssignState(style.focused);
            AssignState(style.hover);
            AssignState(style.active);
            AssignState(style.onNormal);
            AssignState(style.onFocused);
            AssignState(style.onHover);
            AssignState(style.onActive);
        }
示例#3
0
        public void SyncWithLayout(YogaNode targetNode)
        {
            targetNode.Flex = float.NaN;

            float fb = FlexBasisToFloat().GetSpecifiedValueOrDefault(float.NaN);

            if (fb == -1f)
            {
                targetNode.FlexBasis = YogaValue.Auto();
            }
            else
            {
                targetNode.FlexBasis = fb;
            }

            targetNode.FlexGrow          = flexGrow.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.FlexShrink        = flexShrink.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Left              = positionLeft.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Top               = positionTop.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Right             = positionRight.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Bottom            = positionBottom.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MarginLeft        = marginLeft.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MarginTop         = marginTop.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MarginRight       = marginRight.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MarginBottom      = marginBottom.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.PaddingLeft       = paddingLeft.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.PaddingTop        = paddingTop.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.PaddingRight      = paddingRight.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.PaddingBottom     = paddingBottom.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.BorderLeftWidth   = borderLeftWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.BorderTopWidth    = borderTopWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.BorderRightWidth  = borderRightWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.BorderBottomWidth = borderBottomWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Width             = width.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.Height            = height.GetSpecifiedValueOrDefault(float.NaN);

            PositionType posType = (PositionType)positionType.value;

            switch (posType)
            {
            case PositionType.Absolute:
            case PositionType.Manual:
                targetNode.PositionType = YogaPositionType.Absolute;
                break;

            case PositionType.Relative:
                targetNode.PositionType = YogaPositionType.Relative;
                break;
            }

            targetNode.Overflow  = (YogaOverflow)(overflow.value);
            targetNode.AlignSelf = (YogaAlign)(alignSelf.value);
            targetNode.MaxWidth  = maxWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MaxHeight = maxHeight.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MinWidth  = minWidth.GetSpecifiedValueOrDefault(float.NaN);
            targetNode.MinHeight = minHeight.GetSpecifiedValueOrDefault(float.NaN);

            // Note: the following applies to VisualContainer only
            // but it won't cause any trouble and we avoid making this method virtual
            targetNode.FlexDirection  = (YogaFlexDirection)flexDirection.value;
            targetNode.AlignContent   = (YogaAlign)alignContent.GetSpecifiedValueOrDefault((int)DefaultAlignContent);
            targetNode.AlignItems     = (YogaAlign)alignItems.GetSpecifiedValueOrDefault((int)DefaultAlignItems);
            targetNode.JustifyContent = (YogaJustify)justifyContent.value;
            targetNode.Wrap           = (YogaWrap)flexWrap.value;
        }