Class CfgSyntaxHighlighter
java.lang.Object
io.github.zhengzhengyiyi.util.highlighter.CfgSyntaxHighlighter
- All Implemented Interfaces:
HighLighter
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawHighlightedText(DrawContext context, TextRenderer textRenderer, String text, int x, int y, boolean editable) Draws syntax-highlighted text at the specified position.intgetCharIndexFromTokens(TextRenderer textRenderer, String line, int targetX) Finds the character index in the text that corresponds to the given x-coordinate.intgetTextWidth(TextRenderer textRenderer, String text) Calculates the total width of the syntax-highlighted text.intgetTextWidthUpToChar(TextRenderer textRenderer, String line, int charIndex) Calculates the text width from the beginning of the line up to the specified character index.
-
Constructor Details
-
CfgSyntaxHighlighter
public CfgSyntaxHighlighter()
-
-
Method Details
-
getCharIndexFromTokens
Description copied from interface:HighLighterFinds the character index in the text that corresponds to the given x-coordinate.- Specified by:
getCharIndexFromTokensin interfaceHighLighter- Parameters:
textRenderer- the text renderer for measuring text widthline- the text line to search intargetX- the target x-coordinate in pixels- Returns:
- the character index at or before the target x-coordinate
-
getTextWidthUpToChar
Description copied from interface:HighLighterCalculates the text width from the beginning of the line up to the specified character index.- Specified by:
getTextWidthUpToCharin interfaceHighLighter- Parameters:
textRenderer- the text renderer for measuring text widthline- the text line to measurecharIndex- the character index to measure up to (exclusive)- Returns:
- the width in pixels of the text from start to the specified character index
-
drawHighlightedText
public void drawHighlightedText(DrawContext context, TextRenderer textRenderer, String text, int x, int y, boolean editable) Description copied from interface:HighLighterDraws syntax-highlighted text at the specified position.- Specified by:
drawHighlightedTextin interfaceHighLighter- Parameters:
context- the draw context used for renderingtextRenderer- the text renderer for measuring and drawing texttext- the text to be highlighted and drawnx- the x-coordinate of the starting positiony- the y-coordinate of the starting positioneditable- whether the text is in an editable context, which may affect color scheme
-
getTextWidth
Description copied from interface:HighLighterCalculates the total width of the syntax-highlighted text.- Specified by:
getTextWidthin interfaceHighLighter- Parameters:
textRenderer- the text renderer for measuring text widthtext- the text to be measured- Returns:
- the total width in pixels of the highlighted text
-