private static void ApplyStyles(ReactPasswordBoxShadowNode textNode, TextBlock inline)
        {
            if (textNode._fontSize != Unset)
            {
                var fontSize = textNode._fontSize;
                inline.FontSize = fontSize;
            }

            if (textNode._fontStyle.HasValue)
            {
                var fontStyle = textNode._fontStyle.Value;
                inline.FontStyle = fontStyle;
            }

            if (textNode._fontWeight.HasValue)
            {
                var fontWeight = textNode._fontWeight.Value;
                inline.FontWeight = fontWeight;
            }

            if (textNode._fontFamily != null)
            {
                var fontFamily = new FontFamily(textNode._fontFamily);
                inline.FontFamily = fontFamily;
            }
        }
        private static YogaSize MeasurePasswordBox(ReactPasswordBoxShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            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)));
        }
Пример #3
0
        /// <summary>
        /// Formats an inline instance with shadow properties.
        /// </summary>
        /// <param name="textNode">The text shadow node.</param>
        /// <param name="box">The password box.</param>
        /// <param name="measureOnly">Signals if the operation is used only for measurement.</param>
        protected static void FormatPasswordBox(ReactPasswordBoxShadowNode textNode, Control box, bool measureOnly)
        {
            if (textNode._fontSize != Unset)
            {
                var fontSize = textNode._fontSize;
                box.FontSize = fontSize;
            }

            if (textNode._fontStyle.HasValue)
            {
                var fontStyle = textNode._fontStyle.Value;
                box.FontStyle = fontStyle;
            }

            if (textNode._fontWeight.HasValue)
            {
                var fontWeight = textNode._fontWeight.Value;
                box.FontWeight = fontWeight;
            }

            if (textNode._fontFamily != null)
            {
                var fontFamily = new FontFamily(textNode._fontFamily);
                box.FontFamily = fontFamily;
            }
        }
        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);
        }
Пример #5
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)));
        }