private static FrameworkElement CreateElement(string text, IWpfTextView textView, TextFormattingRunProperties format)
        {
            // Constructs the hint block which gets assigned parameter name and fontstyles according to the options
            // page. Calculates a font size 1/4 smaller than the font size of the rest of the editor
            var block = new TextBlock
            {
                FontFamily = format.Typeface.FontFamily,
                FontSize   = format.FontRenderingEmSize - (0.25 * format.FontRenderingEmSize),
                FontStyle  = FontStyles.Normal,
                Foreground = format.ForegroundBrush,

                // Adds a little bit of padding to the left of the text relative to the border
                // to make the text seem more balanced in the border
                Padding           = new Thickness(left: 1, top: 0, right: 0, bottom: 0),
                Text              = text + ":",
                VerticalAlignment = VerticalAlignment.Center,
            };

            // Encapsulates the textblock within a border. Sets the height of the border to be 3/4 of the original
            // height. Gets foreground/background colors from the options menu. The margin is the distance from the
            // adornment to the text and pushing the adornment upwards to create a separation when on a specific line
            var border = new Border
            {
                Background          = format.BackgroundBrush,
                Child               = block,
                CornerRadius        = new CornerRadius(2),
                Height              = textView.LineHeight - (0.25 * textView.LineHeight),
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin              = new Thickness(left: 0, top: -0.20 * textView.LineHeight, right: 5, bottom: 0),
                Padding             = new Thickness(1),

                // Need to set SnapsToDevicePixels and UseLayoutRounding to avoid unnecessary reformatting
                SnapsToDevicePixels = textView.VisualElement.SnapsToDevicePixels,
                UseLayoutRounding   = textView.VisualElement.UseLayoutRounding,
                VerticalAlignment   = VerticalAlignment.Center
            };

            // Need to set these properties to avoid unnecessary reformatting because some dependancy properties
            // affect layout
            TextOptions.SetTextFormattingMode(border, TextOptions.GetTextFormattingMode(textView.VisualElement));
            TextOptions.SetTextHintingMode(border, TextOptions.GetTextHintingMode(textView.VisualElement));
            TextOptions.SetTextRenderingMode(border, TextOptions.GetTextRenderingMode(textView.VisualElement));

            border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            return(border);
        }
Esempio n. 2
0
        private static FrameworkElement CreateElement(
            ImmutableArray <TaggedText> taggedTexts,
            IWpfTextView textView,
            TextFormattingRunProperties format,
            IClassificationFormatMap formatMap,
            ClassificationTypeMap typeMap,
            bool classify)
        {
            // Constructs the hint block which gets assigned parameter name and fontstyles according to the options
            // page. Calculates a font size 1/4 smaller than the font size of the rest of the editor
            var block = new TextBlock
            {
                FontFamily = format.Typeface.FontFamily,
                FontSize   = format.FontRenderingEmSize - (0.25 * format.FontRenderingEmSize),
                FontStyle  = FontStyles.Normal,
                Foreground = format.ForegroundBrush,

                // Adds a little bit of padding to the left of the text relative to the border
                // to make the text seem more balanced in the border
                Padding           = new Thickness(left: 1, top: 0, right: 1, bottom: 0),
                VerticalAlignment = VerticalAlignment.Center,
            };

            var(trimmedTexts, leftPadding, rightPadding) = Trim(taggedTexts);

            foreach (var taggedText in trimmedTexts)
            {
                var run = new Run(taggedText.ToVisibleDisplayString(includeLeftToRightMarker: true));

                if (classify && taggedText.Tag != TextTags.Text)
                {
                    var properties = formatMap.GetTextProperties(typeMap.GetClassificationType(taggedText.Tag.ToClassificationTypeName()));
                    var brush      = properties.ForegroundBrush.Clone();
                    run.Foreground = brush;
                }

                block.Inlines.Add(run);
            }

            // Encapsulates the textblock within a border. Sets the height of the border to be 3/4 of the original
            // height. Gets foreground/background colors from the options menu. The margin is the distance from the
            // adornment to the text and pushing the adornment upwards to create a separation when on a specific line

            // If the tag is started or followed by a space, we trim that off but represent the space as buffer on hte
            // left or right side.
            var left  = leftPadding * 5;
            var right = rightPadding * 5;

            var border = new Border
            {
                Background          = format.BackgroundBrush,
                Child               = block,
                CornerRadius        = new CornerRadius(2),
                Height              = textView.LineHeight - (0.25 * textView.LineHeight),
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin              = new Thickness(left, top: -0.20 * textView.LineHeight, right, bottom: 0),
                Padding             = new Thickness(1),

                // Need to set SnapsToDevicePixels and UseLayoutRounding to avoid unnecessary reformatting
                SnapsToDevicePixels = textView.VisualElement.SnapsToDevicePixels,
                UseLayoutRounding   = textView.VisualElement.UseLayoutRounding,
                VerticalAlignment   = VerticalAlignment.Center
            };

            // Need to set these properties to avoid unnecessary reformatting because some dependancy properties
            // affect layout
            TextOptions.SetTextFormattingMode(border, TextOptions.GetTextFormattingMode(textView.VisualElement));
            TextOptions.SetTextHintingMode(border, TextOptions.GetTextHintingMode(textView.VisualElement));
            TextOptions.SetTextRenderingMode(border, TextOptions.GetTextRenderingMode(textView.VisualElement));

            border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            return(border);
        }
Esempio n. 3
0
        private static FrameworkElement CreateElement(
            ImmutableArray <TaggedText> taggedTexts,
            IWpfTextView textView,
            TextFormattingRunProperties format,
            IClassificationFormatMap formatMap,
            ClassificationTypeMap typeMap,
            bool classify)
        {
            // Constructs the hint block which gets assigned parameter name and fontstyles according to the options
            // page. Calculates a inline tag that will be 3/4s the size of a normal line. This shrink size tends to work
            // well with VS at any zoom level or font size.
            var block = new TextBlock
            {
                FontFamily = format.Typeface.FontFamily,
                FontSize   = 0.75 * format.FontRenderingEmSize,
                FontStyle  = FontStyles.Normal,
                Foreground = format.ForegroundBrush,
                // Adds a little bit of padding to the left of the text relative to the border to make the text seem
                // more balanced in the border
                Padding = new Thickness(left: 2, top: 0, right: 2, bottom: 0)
            };

            var(trimmedTexts, leftPadding, rightPadding) = Trim(taggedTexts);

            foreach (var taggedText in trimmedTexts)
            {
                var run = new Run(taggedText.ToVisibleDisplayString(includeLeftToRightMarker: true));

                if (classify && taggedText.Tag != TextTags.Text)
                {
                    var properties = formatMap.GetTextProperties(typeMap.GetClassificationType(taggedText.Tag.ToClassificationTypeName()));
                    var brush      = properties.ForegroundBrush.Clone();
                    run.Foreground = brush;
                }

                block.Inlines.Add(run);
            }

            block.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            // Encapsulates the textblock within a border. Gets foreground/background colors from the options menu.
            // If the tag is started or followed by a space, we trim that off but represent the space as buffer on hte
            // left or right side.
            var left  = leftPadding * 5;
            var right = rightPadding * 5;

            var border = new Border
            {
                Background        = format.BackgroundBrush,
                Child             = block,
                CornerRadius      = new CornerRadius(2),
                VerticalAlignment = VerticalAlignment.Bottom,
                Margin            = new Thickness(left, top: 0, right, bottom: 0),
            };

            // gets pixel distance of baseline to top of the font height
            var dockPanelHeight = format.Typeface.FontFamily.Baseline * format.FontRenderingEmSize;
            var dockPanel       = new DockPanel
            {
                Height        = dockPanelHeight,
                LastChildFill = false,
                // VerticalAlignment is set to Top because it will rest to the top relative to the stackpanel
                VerticalAlignment = VerticalAlignment.Top
            };

            dockPanel.Children.Add(border);
            DockPanel.SetDock(border, Dock.Bottom);

            var stackPanel = new StackPanel
            {
                // Height set to align the baseline of the text within the TextBlock with the baseline of text in the editor
                Height      = dockPanelHeight + (block.DesiredSize.Height - (block.FontFamily.Baseline * block.FontSize)),
                Orientation = Orientation.Vertical
            };

            stackPanel.Children.Add(dockPanel);
            // Need to set these properties to avoid unnecessary reformatting because some dependancy properties
            // affect layout
            TextOptions.SetTextFormattingMode(stackPanel, TextOptions.GetTextFormattingMode(textView.VisualElement));
            TextOptions.SetTextHintingMode(stackPanel, TextOptions.GetTextHintingMode(textView.VisualElement));
            TextOptions.SetTextRenderingMode(stackPanel, TextOptions.GetTextRenderingMode(textView.VisualElement));

            return(stackPanel);
        }
 void UpdateViewLayoutOptionsCache(FrameworkElement view)
 {
     m_textRenderingMode  = TextOptions.GetTextRenderingMode(view);
     m_textHintingMode    = TextOptions.GetTextHintingMode(view);
     m_textFormattingMode = TextOptions.GetTextFormattingMode(view);
 }
 Boolean AreViewLayoutOptionsChanged(FrameworkElement view)
 {
     return((TextOptions.GetTextRenderingMode(view) != m_textRenderingMode) ||
            (TextOptions.GetTextHintingMode(view) != m_textHintingMode) ||
            (TextOptions.GetTextFormattingMode(view) != m_textFormattingMode));
 }
Esempio n. 6
0
        private static FrameworkElement CreateElement(
            ImmutableArray <TaggedText> taggedTexts,
            IWpfTextView textView,
            TextFormattingRunProperties format,
            IClassificationFormatMap formatMap,
            ClassificationTypeMap typeMap,
            bool classify)
        {
            // Constructs the hint block which gets assigned parameter name and fontstyles according to the options
            // page. Calculates a inline tag that will be 3/4s the size of a normal line. This shrink size tends to work
            // well with VS at any zoom level or font size.

            var block = new TextBlock
            {
                FontFamily = format.Typeface.FontFamily,
                FontSize   = 0.75 * format.FontRenderingEmSize,
                FontStyle  = FontStyles.Normal,
                Foreground = format.ForegroundBrush,

                // Adds a little bit of padding to the left of the text relative to the border
                // to make the text seem more balanced in the border
                Padding           = new Thickness(left: 1, top: 0, right: 1, bottom: 0),
                VerticalAlignment = VerticalAlignment.Center,
            };

            var(trimmedTexts, leftPadding, rightPadding) = Trim(taggedTexts);

            foreach (var taggedText in trimmedTexts)
            {
                var run = new Run(taggedText.ToVisibleDisplayString(includeLeftToRightMarker: true));

                if (classify && taggedText.Tag != TextTags.Text)
                {
                    var properties = formatMap.GetTextProperties(typeMap.GetClassificationType(taggedText.Tag.ToClassificationTypeName()));
                    var brush      = properties.ForegroundBrush.Clone();
                    run.Foreground = brush;
                }

                block.Inlines.Add(run);
            }

            // Encapsulates the textblock within a border. Gets foreground/background colors from the options menu.

            // If the tag is started or followed by a space, we trim that off but represent the space as buffer on hte
            // left or right side.
            var left  = leftPadding * 5;
            var right = rightPadding * 5;

            var border = new Border
            {
                Background   = format.BackgroundBrush,
                Child        = block,
                CornerRadius = new CornerRadius(2),

                // Place 3 pixels above/below the border object.  This works well as the highlighting lines are 2px
                // each, giving us 1 px of space on both side of the inline tag and them.  This gives the inline tag
                // an appropriate floating-halfway feeling on the line.
                Margin = new Thickness(left, top: 3, right, bottom: 3),
            };

            // Need to set these properties to avoid unnecessary reformatting because some dependancy properties
            // affect layout
            TextOptions.SetTextFormattingMode(border, TextOptions.GetTextFormattingMode(textView.VisualElement));
            TextOptions.SetTextHintingMode(border, TextOptions.GetTextHintingMode(textView.VisualElement));
            TextOptions.SetTextRenderingMode(border, TextOptions.GetTextRenderingMode(textView.VisualElement));

            border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            return(border);
        }