private static YogaSize MeasurePasswordBox(ReactPasswordBoxShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

            var normalizedWidth = Math.Max(0,
                                           (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width));

            var normalizedHeight = Math.Max(0,
                                            (YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height));

            var passwordChar   = GetDefaultPasswordChar();
            var normalizedText = !string.IsNullOrEmpty(textInputNode._text)
                ? new string(passwordChar[0], textInputNode._text.Length)
                : passwordChar;

            var textBlock = new TextBlock
            {
                Text = normalizedText,
            };

            ApplyStyles(textInputNode, textBlock);

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

            return(MeasureOutput.Make(
                       (float)Math.Ceiling(width),
                       (float)Math.Ceiling(textBlock.ActualHeight)));
        }
        private static YogaSize MeasureTextInput(ReactPasswordBoxShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

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

            var normalizedWidth = Math.Max(0,
                                           (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width)
                                           - textInputNode._computedPadding[0]
                                           - textInputNode._computedPadding[2]
                                           - (YogaConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth)
                                           - (YogaConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth));
            var normalizedHeight = Math.Max(0, YogaConstants.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 textBlock = new TextBlock
                {
                    TextWrapping = TextWrapping.Wrap,
                };

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

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

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

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

                return(MeasureOutput.Make(
                           (float)Math.Ceiling(width),
                           (float)Math.Ceiling(finalizedHeight)));
            });

            return(task.Result);
        }
Exemple #3
0
        private static YogaSize MeasureTextInput(ReactPasswordBoxShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

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

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

            // TODO: Measure text with DirectWrite or other API that does not
            // require dispatcher access. Currently, we're instantiating a
            // second CoreApplicationView (that is never activated) and using
            // its Dispatcher thread to calculate layout.
            var textBlock = new TextBlock
            {
                TextWrapping = TextWrapping.Wrap,
            };

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

            FormatTextElement(textInputNode, inline);
            textBlock.Inlines.Add(inline);

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

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

            var finalizedHeight = (float)textBlock.DesiredSize.Height;

            finalizedHeight += textInputNode._computedPadding[1];
            finalizedHeight += textInputNode._computedPadding[3];
            finalizedHeight += YogaConstants.IsUndefined(borderTopWidth) ? 0 : borderTopWidth;
            finalizedHeight += YogaConstants.IsUndefined(borderBottomWidth) ? 0 : borderBottomWidth;

            return(MeasureOutput.Make(
                       (float)Math.Ceiling(width),
                       (float)Math.Ceiling(finalizedHeight)));
        }