How do you create an adornment layer to display vertical (column) lines

SyntaxEditor for Windows Forms Forum

Posted 9 months ago by Simon Sprott
Version: 20.1.0403
Avatar

I'm trying to create an adornment layer to display vertical columns (from a list).

I've adapted the drawing code in the ColorPreviewSyntaxLanguage sample to draw the lines from the adornment layer

var pt1 = new Point(adornment.Location.X, 0);
var pt2 = new Point(adornment.Location.X, context.TextAreaBounds.Bottom);

pt1.Offset(context.TextAreaBounds.Location);
pt2.Offset(context.TextAreaBounds.Location);

context.DrawLine(pt1, pt2, Pens.Red);

And created a ColumnTagger class based on TaggerBase<ColumnMarkerTag> which outputs a list of tags based on my list of columns. This all pretty much works, however, if I add an entry to the columns list its not re-drawn.

return ((ColumnMarkerSyntaxLanguage)this.Document.Language).Columns.Select(
c => new TagSnapshotRange<ColumnMarkerTag>(
new TextSnapshotRange(snapshotRanges[0].Snapshot, c, c + 1),
new ColumnMarkerTag() { ColumnIndex = c }));

where ColumnMarkerSyntaxLanguage has the property

public List<int> Columns { get; } = new List<int>();

I've tried invalidating the editor but it doesn't seem to cause the adorments to refresh. The only thing that causes a refresh is a change to the actual document. I think this is possibly as I'm attaching the tag to a text range that potentially does not exist (the document could be empty). How do I force an adornment refresh?

Note: this adornment layer was built into the older version of the syntax editor control, would it be possible to re-add it into the current version?

Comments (3)

Posted 9 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Simon,

The AdornmentsColorPreview QuickStart probably isn't a good one to look at since that one is geared to only render over a text range.  Whereas the AdornmentsWatermark QuickStart is more like what you want since that renders behind the entire editor.

If you call the editor.InvalidateViews() method, it should refresh the adornment.

Could you clarify what you meant by the older version's adornment layer and what is missing?  The current adornment system is in sync with the WPF and UWP versions of SyntaxEditor so that they can all share code.  I'm not sure that we would be adding any other ways of doing adornments.


Actipro Software Support

Posted 9 months ago by Simon Sprott
Avatar

I looked at that sample initially, but couldn't find a method to convert a column index to a location (drawing Point).

Posted 9 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Simon,

In that QuickStart's OnDrawAdornment method, you could add something like this to draw a vertical line in front of the 12th column:

var columnIndex = 12;
var x = textAreaBounds.X - context.View.ScrollState.HorizontalAmount + columnIndex * context.View.DefaultCharacterWidth;
context.DrawLine(new Point(x, textAreaBounds.Y), new Point(x, textAreaBounds.Bottom), Color.Red, LineKind.Solid, 1);


Actipro Software Support

The latest build of this product (v21.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.