Add annotation option

The script tip may seem less out-of-place if the code being tipped has some sort of visual cue, like a color change.

This implementation shows a proof-of-concept of how that might look by drawing a TextBlock directly over the existing text. But because of how text is rendered, it looks... terrible. A better thing to do would be to not draw the under-text, and draw the caret over both layers. This requires a more specialized control and could also be used for general syntax-highlighting. Revisit later.
This commit is contained in:
Benjamin Popp 2020-04-27 23:27:53 -05:00
parent 0f73e7b3e4
commit e03ba2bc12
2 changed files with 24 additions and 1 deletions

View File

@ -402,8 +402,12 @@
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Label}" Margin="2,0"/>
<TextBox Margin="5" Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}"
<Grid Margin="5">
<TextBox Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}"
AcceptsReturn="True" FontFamily="Consolas" SelectionChanged="CodeToolContentsSelectionChanged"/>
<TextBlock Visibility="{Binding IsOpen, ElementName=CodeContentsPopup, Converter={StaticResource BoolToVisibility}}"
HorizontalAlignment="Left" VerticalAlignment="Top" IsHitTestVisible="False" FontFamily="Consolas" FontWeight="Bold"/>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>

View File

@ -278,6 +278,25 @@ namespace HavenSoft.HexManiac.WPF.Controls {
}
CodeContentsPopup.IsOpen = true;
// var selectedLine = textbox.Text.Split(Environment.NewLine)[linesBeforeSelection];
// Annotate(textbox, textbox.SelectionStart, selectedLine.Split(' ')[0], Brush(nameof(Theme.Accent)));
}
private void Annotate(TextBox box, int index, string annotation, SolidColorBrush brush) {
var grid = box.Parent as Grid;
if (grid == null) return;
if (grid.Children.Count != 2) return;
var annotationBlock = grid.Children[1] as TextBlock;
if (annotationBlock == null) return;
var linesBeforeSelection = box.Text.Substring(0, index).Split(Environment.NewLine).Length - 1;
var totalLines = box.Text.Split(Environment.NewLine).Length;
var lineHeight = box.ExtentHeight / totalLines;
var verticalStart = lineHeight * linesBeforeSelection;
annotationBlock.Text = annotation;
annotationBlock.Margin = new Thickness(3, verticalStart + 1, 0, 0);
annotationBlock.Foreground = brush;
}
private void HeaderMouseDown(object sender, MouseButtonEventArgs e) {