I was wondering if there is a straightforward way to display line numbers with StyledText
text field - even if lines are wrapped. I'm using it in my application and if content gets to big, some line numbers would be nice.
Thank you.
I was wondering if there is a straightforward way to display line numbers with StyledText
text field - even if lines are wrapped. I'm using it in my application and if content gets to big, some line numbers would be nice.
Thank you.
I believe that using a LineStyleListener should work. Something along the lines of:
The key is org.eclipse.swt.custom.Bullet. It's basically a symbol (or in our case a number) you can add to the beginning of a line.
As a side-note for colouring the line numbers:
where
LINE_NUMBER_BG
andLINE_NUMBER_FG
might be a RGB object such as:This is a way to use bullets that updates the numbers when the content changes:
This is my working implementation.
Note that the possible overhead of syntax highlighting recalculation when calling redraw() is likely to be acceptable, because lineGetStyle() are only called with lines currently on screen.