Skip to content

XUICELine

Inherits XUITextLine

Description

Represents a single line of text in the XUICodeEditor.

Properties

Name Type Read-Only
ColumnLength Integer
Contents String
IndentLevel Integer
IsContinuation Boolean
IsOnlyNonAlpha Boolean
LineManager XUICELineManager
mIndentLevel Integer
mOwnerRef WeakRef
mTextEndX Double
mTextStartX Double
mTextStartY Double
mTopLeftY Double
TextEndX Double
TextStartX Double
TextStartY Double
Tokens() XUICELineToken
Unmatched Boolean
Value String

Methods

Name Parameters Returns
CharactersFromCaretPos startPos As Integer, count As Integer String
CharactersFromColumn startCol As Integer, count As Integer String
CharactersInSelection selection As XUITextSelection String
CharactersToColumn column As Integer String
ChopCharacters count As Integer String
ChopCharactersFrom column As Integer, shouldTokenise As Boolean String
ColumnAtX x As Integer, g As Graphics Integer
Constructor owner As XUICELineManager, lineNumber As Integer, startPos As Integer, lineContents As String, shouldTokenise As Boolean
DeleteCharacterAtCaretPos caretPos As Integer, shouldTokenise As Boolean
DeleteCharactersFromCaretPos caretPos As Integer, count As Integer, shouldTokenise As Boolean
DeleteCharactersFromEnd count As Integer, shouldTokenise As Boolean
Draw g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double, containsCaret As Boolean, maxLineNumWidth As Double
DrawBlockLines g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double
DrawDebugHighlight g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double
DrawLineNumber g As Graphics, topLeftY As Double, gutterWidth As Double, lineH As Double
DrawSelection selectedColumns As XUICESelectedColumns, g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double
DrawText g As Graphics, s As String, x As Double, y As Double, wrapWidth As Double, condense As Boolean
FirstToken XUICELineToken
HighlightDelimiter delimiter As XUICELineToken, g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double
IndentWidth charWidth As Double Double
Insert column As Integer, s As String Integer
LastToken XUICELineToken
Left count As Integer String
NextWordEnd caretPos As Integer Integer
PopCharacters count As Integer, shouldTokenise As Boolean String
PreviousWordStart caretPos As Integer Integer
Right count As Integer String
SetContents value As String, shouldTokenise As Boolean
TokenAtColumn column As Integer XUICELineToken
Tokenise
TokenSelectionOverlap t As XUICELineToken, selection As XUICESelectedColumns Pair
WidthToCaretPos caretPos As Integer, g As Graphics Double
WidthToColumn column As Integer, g As Graphics, ignoreIdentation As Boolean Double
WordToColumn column As Integer String

Constants

Name Type
COLUMNS_PER_INDENT Double
ELLIPSIS String

COLUMNS_PER_INDENT As Double The number of columns each level of indentation is equivalent to.


ELLIPSIS As String The string to draw when there are autocomplete suggestions available.


Property Descriptions

ColumnLength As Integer

The length of this line in columns. A combination of the number of characters and the amount of indentation.


Contents As String

The read only contents of this line. To alter use SetContents().


IndentLevel As Integer

This line's level of indentation (0 = no indentation). Clamped to >= 0.


IsContinuation As Boolean

True if this line is a continuation of the line above.


IsOnlyNonAlpha As Boolean

True if this line contains only non-alphanumeric characters.


LineManager As XUICELineManager

The line manager that owns this line.


mIndentLevel As Integer

Backing field for the IndentLevel computed property.


mOwnerRef As WeakRef

A weak reference to this line's owning line manager.


mTextEndX As Double

Backing field for the TextEndX computed property.


mTextStartX As Double

Backing field for the TextStartX computed property.


mTextStartY As Double

Backing field for the computed TextStartY property.


mTopLeftY As Double

The top left Y coordinate that this line is drawn at.


TextEndX As Double

The X coordinate of the end of this line's text computed during its last draw.


TextStartX As Double

The X coordinate of the start of this line's text computed during its last draw. Includes indentation.


TextStartY As Double

The Y coordinate of the start of this line's text computed during its last draw.


Tokens() As XUICELineToken

This line's tokens.


Unmatched As Boolean

True if this line is part of an unmatched block structure.


Value As String

We override TextLine.Value because the editor should use Contents instead.


Method Descriptions

CharactersFromCaretPos(startPos As Integer, count As Integer) As String

Returns count characters from this line starting at startPos.


CharactersFromColumn(startCol As Integer, count As Integer) As String

Returns count characters from this line starting at the 0-based startCol.


CharactersInSelection(selection As XUITextSelection) As String

Returns the characters enclosed by the passed selection.


CharactersToColumn(column As Integer) As String

Returns the characters up to but not including column.


ChopCharacters(count As Integer) As String

Chops (removes) count characters from the end of the line and returns them.


ChopCharactersFrom(column As Integer, shouldTokenise As Boolean) As String

Chops (removes) the characters from column to the end of the line and returns them.


ColumnAtX(x As Integer, g As Graphics) As Integer

Returns the column at pixel position x where 0 is the line start. Returns -1 if out of range.

x is relative to this line's TextStartX property. g is the graphics context used to measure text width.


Constructor(owner As XUICELineManager, lineNumber As Integer, startPos As Integer, lineContents As String, shouldTokenise As Boolean)

Default constructor.

  • owner is the XUILineManager that manages this line. Will be kept as a WeakRef.
  • lineNumber is this line's 1-based line number.
  • startPos is the 0-based position in the source code that this line begins at.
  • lineContents is the contents of this line.
  • shouldTokenise determines if this line should be tokenised by the line manager's code editor's active formatter upon instantiation. Default is True.

DeleteCharacterAtCaretPos(caretPos As Integer, shouldTokenise As Boolean)

Deletes the character at caretPos from this line.

Raises an InvalidArgumentException if caretPos is out of range.


DeleteCharactersFromCaretPos(caretPos As Integer, count As Integer, shouldTokenise As Boolean)

Deletes count characters from this line beginning at caretPos.


DeleteCharactersFromEnd(count As Integer, shouldTokenise As Boolean)

Deletes count characters from the end of the line.


Draw(g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double, containsCaret As Boolean, maxLineNumWidth As Double)

Draws this line to g.

  • topLeftX is the X coord of the top left corner of the line.
  • topLeftY is the Y coord of the top left corner of the line.
  • lineH is the height of the line.
  • gutterWidth is the width of the gutter.
  • maxLineNumWidth is the width of the bounding rectangle around the longest line number in the gutter.

A line includes the gutter, any spacing for indentation and the line contents itself.

Anti-aliasing needs to be disabled whenever we draw on Windows except for text (which looks rubbish if anti-aliasing is off).

Assumes that the graphics context has anti-aliasing off in Windows builds.


DrawBlockLines(g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double)

Draws this line's block lines.

Block lines are a visual representation of the connections between blocks. We can quickly achieve this by drawing a vertical line at each indentation level.


DrawDebugHighlight(g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double)

Draws a rounded rect around the text on this line. Used to highlight a line that is being debugged.


DrawLineNumber(g As Graphics, topLeftY As Double, gutterWidth As Double, lineH As Double)

Draws a the line number to the gutter in g.

gutterWidth is the width of the this line's canvas' gutter. topLeftY is the top left corner of the line. lineH is the height of the line.


DrawSelection(selectedColumns As XUICESelectedColumns, g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double)

Draws the selected columns within this line.


DrawText(g As Graphics, s As String, x As Double, y As Double, wrapWidth As Double, condense As Boolean)

Draws an anti-aliased string s at the specified location in g.

  • s is the string to draw.
  • x is the x coordinate.
  • y is the y coordinate of the text baseline.
  • wrapWidth is the width the text will wrap at.
  • If condense is True then the string may be truncated with an ellipsis.

This is essentially a wrapper to the Graphics.DrawText method. It exists because we need to disable anti-aliasing in the graphics contexts on Windows but it needs to be re-enabled when drawing text. Rather than litter the code base with calls to toggle the anti-aliasing state, this method does it for us.


FirstToken() As XUICELineToken

Returns the first token of this line or Nil if there are no tokens.


HighlightDelimiter(delimiter As XUICELineToken, g As Graphics, topLeftX As Double, topLeftY As Double, lineH As Double, gutterWidth As Double)

Highlights the passed delimiter on this line.


IndentWidth(charWidth As Double) As Double

Returns the width of the indentation at the front of this line.

charWidth is the current width of a character in the editor.


Insert(column As Integer, s As String) As Integer

Inserts s into this line at column. Returns the caret position following the insertion.

Raises an InvalidArgumentException if column is out of range. Assumes that s is not empty and does not contain newlines.


LastToken() As XUICELineToken

Returns the last token on this line or Nil if there are no tokens.


Left(count As Integer) As String

Returns count left-most characters from this line.


NextWordEnd(caretPos As Integer) As Integer

Returns the caret position of the end of the word after the caretPos.

If the caret is within the last word on this line then it returns the end position for the line.

Raises an InvalidArgumentException if caretPos is out of range for this line.


PopCharacters(count As Integer, shouldTokenise As Boolean) As String

Pops the specified number of characters from the end of this line and returns them.

If count > number of characters on the line we return the whole line. Assumes count > 0.


PreviousWordStart(caretPos As Integer) As Integer

Returns the caret pos of the start of the word before the caretPos.

If caretPos is within the first word on the line then it returns the line start position. Raises an InvalidArgumentException if caretPos is out of range for this line.


Right(count As Integer) As String

Returns count right-most characters from this line.


SetContents(value As String, shouldTokenise As Boolean)

Sets the contents of this line to value, marks the line as dirty and optionally triggers tokenisation.

Assumes that there are no newline characters in value.


TokenAtColumn(column As Integer) As XUICELineToken

Returns the token at the specified column or Nil if there isn't one.


Tokenise()

Re-tokenises this line and any others required (depending on mode).


TokenSelectionOverlap(t As XUICELineToken, selection As XUICESelectedColumns) As Pair

Returns a Pair containing the first and last columns of the token contained by the selection or Nil if the token is not selected.

t is the token we want to check if enclosed by the passed selection. selection is a selection representing the columns in this line that are selected.

The returned pair's structure is: Left = 0-based column of this token where the selection starts Right = 0-based column of this token where the selection ends.

Let's suppose the token has the lexeme "Hello" and characters "ell" are selected by the passed selection. We will return 1:3 (as the first character selected is at column 1 and the last character selected is at column 3). The important thing to remember is that the returned columns are local to this token, not the line.

Assumes that at least part of this line is within the passed selection so there is at least a chance the passed token is selected.


WidthToCaretPos(caretPos As Integer, g As Graphics) As Double

Returns the width of the text of this line up and including the character at caretPos in g.

caretPos is the 0-based caret position, not the offset of the character in this line. Assumes the g has the correct font size and family set.


WidthToColumn(column As Integer, g As Graphics, ignoreIdentation As Boolean) As Double

The width of this line up to column.

g is required to compute the width of the string.

Does not include the gutter width. Does not factor in padding around the text or the gutter.


WordToColumn(column As Integer) As String

Returns the word running up to (not-including) 0-based column. Returns "" if there isn't one.