Interface HighLighter

All Known Implementing Classes:
CfgSyntaxHighlighter, FileType.DefaultHighlighter, JsonSyntaxHighlighter, PropertiesSyntaxHighlighter, TextSyntaxHighlighter, TomlSyntaxHighlighter, YamlSyntaxHighlighter

public interface HighLighter
A syntax highlighter interface that provides methods for text rendering and measurement with syntax highlighting capabilities. Implementations of this interface should provide syntax highlighting for specific programming languages or data formats by tokenizing text and applying appropriate colors to different token types.
  • Method Details

    • drawHighlightedText

      void drawHighlightedText(DrawContext context, TextRenderer textRenderer, String text, int x, int y, boolean editable)
      Draws syntax-highlighted text at the specified position.
      Parameters:
      context - the draw context used for rendering
      textRenderer - the text renderer for measuring and drawing text
      text - the text to be highlighted and drawn
      x - the x-coordinate of the starting position
      y - the y-coordinate of the starting position
      editable - whether the text is in an editable context, which may affect color scheme
    • getTextWidth

      int getTextWidth(TextRenderer textRenderer, String text)
      Calculates the total width of the syntax-highlighted text.
      Parameters:
      textRenderer - the text renderer for measuring text width
      text - the text to be measured
      Returns:
      the total width in pixels of the highlighted text
    • getCharIndexFromTokens

      int getCharIndexFromTokens(TextRenderer textRenderer, String line, int targetX)
      Finds the character index in the text that corresponds to the given x-coordinate.
      Parameters:
      textRenderer - the text renderer for measuring text width
      line - the text line to search in
      targetX - the target x-coordinate in pixels
      Returns:
      the character index at or before the target x-coordinate
    • getTextWidthUpToChar

      int getTextWidthUpToChar(TextRenderer textRenderer, String line, int charIndex)
      Calculates the text width from the beginning of the line up to the specified character index.
      Parameters:
      textRenderer - the text renderer for measuring text width
      line - the text line to measure
      charIndex - the character index to measure up to (exclusive)
      Returns:
      the width in pixels of the text from start to the specified character index