public static float GetPaddingValue(this CSSNode node, CSSSpacingType spacingType)
        {
            var padding = node.GetPadding(spacingType);

            if (!CSSConstants.IsUndefined(padding))
            {
                return(padding);
            }

            if (spacingType == CSSSpacingType.Left || spacingType == CSSSpacingType.Right)
            {
                padding = node.GetPadding(CSSSpacingType.Horizontal);
            }

            if (!CSSConstants.IsUndefined(padding))
            {
                return(padding);
            }

            if (spacingType == CSSSpacingType.Top || spacingType == CSSSpacingType.Bottom)
            {
                padding = node.GetPadding(CSSSpacingType.Vertical);
            }

            if (!CSSConstants.IsUndefined(padding))
            {
                return(padding);
            }

            return(node.GetPadding(CSSSpacingType.All));
        }
        private static MeasureOutput MeasureText(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.
            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                var textBlock = new TextBlock
                {
                    TextAlignment = TextAlignment.Left,
                    TextTrimming  = TextTrimming.CharacterEllipsis,
                };

                var textNode = (ReactTextShadowNode)node;
                textNode.UpdateTextBlockCore(textBlock, true);

                foreach (var child in textNode.Children)
                {
                    textBlock.Inlines.Add(ReactInlineShadowNodeVisitor.Apply(child));
                }

                var normalizedWidth  = CSSConstants.IsUndefined(width) ? double.PositiveInfinity : width;
                var normalizedHeight = CSSConstants.IsUndefined(height) ? double.PositiveInfinity : height;
                textBlock.Measure(new Size(normalizedWidth, normalizedHeight));
                return(new MeasureOutput(
                           (float)textBlock.DesiredSize.Width,
                           (float)textBlock.DesiredSize.Height));
            });

            return(task.Result);
        }
        /// <summary>
        /// Measures the width and height of a <see cref="ProgressRing"/>.
        /// </summary>
        /// <param name="node">The css style of the rendered <see cref="ProgressRing"/>.</param>
        /// <param name="width">The parameterized native width of the control.</param>
        /// <param name="widthMode">The width measurement mode.</param>
        /// <param name="height">The parameterized native height of the control.</param>
        /// <param name="heightMode">The height measurement mode.</param>
        /// <returns>The measurement <see cref="MeasureOutput"/> for the <see cref="ProgressRing"/> component.</returns>
        private static MeasureOutput MeasureProgressRing(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            var normalizedWidth  = !CSSConstants.IsUndefined(width) ? width : 20;
            var normalizedHeight = !CSSConstants.IsUndefined(height) ? height : 20;

            return(new MeasureOutput(normalizedWidth, normalizedHeight));
        }
Пример #4
0
        private static MeasureOutput MeasureTextInput(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            var textInputNode = (ReactPasswordBoxShadowNode)node;

            textInputNode._computedPadding = textInputNode.GetComputedPadding();

            var borderLeftWidth  = textInputNode.GetBorder(CSSSpacingType.Left);
            var borderRightWidth = textInputNode.GetBorder(CSSSpacingType.Right);

            var normalizedWidth = Math.Max(0,
                                           (CSSConstants.IsUndefined(width) ? double.PositiveInfinity : width)
                                           - textInputNode._computedPadding[0]
                                           - textInputNode._computedPadding[2]
                                           - (CSSConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth)
                                           - (CSSConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth));
            var normalizedHeight = Math.Max(0, CSSConstants.IsUndefined(height) ? double.PositiveInfinity : height);

            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.
            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                var textNode = (ReactPasswordBoxShadowNode)node;

                var textBlock = new TextBlock
                {
                    TextWrapping = TextWrapping.Wrap,
                };

                var passwordChar   = GetDefaultPasswordChar();
                var normalizedText = !string.IsNullOrEmpty(textNode._text)
                    ? new string(passwordChar[0], textNode._text.Length)
                    : passwordChar;
                var inline = new Run {
                    Text = normalizedText
                };
                FormatTextElement(textNode, inline);
                textBlock.Inlines.Add(inline);

                textBlock.Measure(new Size(normalizedWidth, normalizedHeight));

                var borderTopWidth    = textInputNode.GetBorder(CSSSpacingType.Top);
                var borderBottomWidth = textInputNode.GetBorder(CSSSpacingType.Bottom);

                var finalizedHeight = (float)textBlock.DesiredSize.Height;
                finalizedHeight    += textInputNode._computedPadding[1];
                finalizedHeight    += textInputNode._computedPadding[3];
                finalizedHeight    += CSSConstants.IsUndefined(borderTopWidth) ? 0 : borderTopWidth;
                finalizedHeight    += CSSConstants.IsUndefined(borderBottomWidth) ? 0 : borderBottomWidth;

                return(new MeasureOutput(width, finalizedHeight));
            });

            return(task.Result);
        }
        public static float GetPaddingSpace(this CSSNode node, CSSSpacingType spacingType)
        {
            var padding = node.GetPaddingValue(spacingType);

            return(CSSConstants.IsUndefined(padding)
                ? 0.0f
                : padding);
        }
Пример #6
0
        public void TestCopyStyle()
        {
            CSSNode node0 = new CSSNode();

            Assert.IsTrue(CSSConstants.IsUndefined(node0.MaxHeight));

            CSSNode node1 = new CSSNode();

            node1.MaxHeight = 100;

            node0.CopyStyle(node1);
            Assert.AreEqual(100, node0.MaxHeight);
        }
        private static MeasureOutput MeasureText(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.
            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                var textBlock = new TextBlock
                {
                    TextWrapping  = TextWrapping.Wrap,
                    TextAlignment = TextAlignment.DetectFromContent,
                    TextTrimming  = TextTrimming.CharacterEllipsis,
                };

                var textNode = (ReactTextShadowNode)node;

                textBlock.CharacterSpacing = textNode._letterSpacing;
                textBlock.LineHeight       = textNode._lineHeight;
                textBlock.MaxLines         = textNode._numberOfLines;
                textBlock.TextAlignment    = textNode._textAlignment;

                textBlock.Inlines.Add(ReactTextShadowNodeInlineVisitor.Apply(node));

                try
                {
                    var normalizedWidth  = CSSConstants.IsUndefined(width) ? double.PositiveInfinity : width;
                    var normalizedHeight = CSSConstants.IsUndefined(height) ? double.PositiveInfinity : height;
                    textBlock.Measure(new Size(normalizedWidth, normalizedHeight));
                    return(new MeasureOutput(
                               (float)Math.Ceiling(textBlock.DesiredSize.Width),
                               (float)Math.Ceiling(textBlock.DesiredSize.Height)));
                }
                finally
                {
                    textBlock.Inlines.Clear();
                }
            });

            return(task.Result);
        }
        /// <summary>
        /// Sets the padding of the shadow node.
        /// </summary>
        /// <param name="spacingType">The spacing type.</param>
        /// <param name="padding">The padding value.</param>
        protected override void SetPaddingCore(CSSSpacingType spacingType, float padding)
        {
            MarkUpdated();
            switch (spacingType)
            {
            case CSSSpacingType.Left:
            case CSSSpacingType.Top:
            case CSSSpacingType.Right:
            case CSSSpacingType.Bottom:
                var index       = (int)spacingType;
                var isUndefined = CSSConstants.IsUndefined(padding);
                SetPadding(spacingType, isUndefined ? s_defaultPaddings[index] : padding);
                _isUserPadding[index] = !isUndefined;
                break;

            default:
                base.SetPaddingCore(spacingType, padding);
                break;
            }
        }
Пример #9
0
        public void TestMultiple()
        {
            CSSNode node = CSSNode.Create(
                positionType: CSSPositionType.Absolute,
                wrap: CSSWrap.Wrap,
                position: new Spacing(top: 6, right: 4),
                margin: new Spacing(bottom: 5, left: 3));

            Assert.AreEqual(CSSFlexDirection.Column, node.FlexDirection);
            Assert.AreEqual(CSSPositionType.Absolute, node.PositionType);
            Assert.AreEqual(CSSWrap.Wrap, node.Wrap);
            Assert.AreEqual(6, node.GetPosition(CSSEdge.Top));
            Assert.IsTrue(CSSConstants.IsUndefined(node.GetPosition(CSSEdge.Bottom)));
            Assert.AreEqual(4, node.GetPosition(CSSEdge.Right));
            Assert.IsTrue(CSSConstants.IsUndefined(node.GetPosition(CSSEdge.Left)));
            Assert.AreEqual(0, node.GetMargin(CSSEdge.Top));
            Assert.AreEqual(5, node.GetMargin(CSSEdge.Bottom));
            Assert.AreEqual(3, node.GetMargin(CSSEdge.Left));
            Assert.AreEqual(0, node.GetMargin(CSSEdge.Right));
        }
        private float GetTextInputPadding(CSSSpacingType spacingType)
        {
            var index           = (int)spacingType;
            var isUserPadding   = _isUserPadding[index];
            var originalPadding = GetPadding(spacingType);

            if (!isUserPadding)
            {
                SetPadding(spacingType, CSSConstants.Undefined);
            }

            var result = this.GetPaddingValue(spacingType);

            if (CSSConstants.IsUndefined(result))
            {
                result = originalPadding;
            }

            SetPadding(spacingType, originalPadding);
            return(result);
        }
        public static float GetTopBorderWidth(this CSSNode node)
        {
            var width = node.GetBorder(CSSSpacingType.Top);

            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            width = node.GetBorder(CSSSpacingType.Vertical);
            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            width = node.GetBorder(CSSSpacingType.All);
            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            return(0.0f);
        }
        public static float GetLeftBorderWidth(this CSSNode node)
        {
            var width = node.GetBorder(CSSSpacingType.Left);

            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            width = node.GetBorder(CSSSpacingType.Horizontal);
            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            width = node.GetBorder(CSSSpacingType.All);
            if (!CSSConstants.IsUndefined(width))
            {
                return(width);
            }

            return(0.0f);
        }
Пример #13
0
        /**
         * Set a spacing value.
         *
         * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM},
         *        {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL}
         * @param value the value for this direction
         * @return {@code true} if the spacing has changed, or {@code false} if the same value was already
         *         set
         */

        internal bool set(int spacingType, float value)
        {
            if (!FloatUtil.floatsEqual(mSpacing[spacingType], value))
            {
                mSpacing[spacingType] = value;

                if (CSSConstants.IsUndefined(value))
                {
                    mValueFlags &= ~sFlagsMap[spacingType];
                }
                else
                {
                    mValueFlags |= sFlagsMap[spacingType];
                }

                mHasAliasesSet =
                    (mValueFlags & sFlagsMap[ALL]) != 0 ||
                    (mValueFlags & sFlagsMap[VERTICAL]) != 0 ||
                    (mValueFlags & sFlagsMap[HORIZONTAL]) != 0;

                return(true);
            }
            return(false);
        }
        private static MeasureOutput MeasureProgressBar(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            var adjustedHeight = CSSConstants.IsUndefined(height) ? 4 : height;

            return(new MeasureOutput(width, adjustedHeight));
        }