Class TextOffset
java.lang.Object
com.github.darksoulq.abyssallib.server.resource.util.TextOffset
Utility for generating invisible font-based glyph offsets to fine-tune horizontal text alignment.
This class uses a custom font provider to register glyphs with specific advance widths. By appending these characters to a string, text following them is shifted horizontally without rendering any visible characters.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.kyori.adventure.text.ComponentgetOffset(int pixelOffset) Converts a pixel offset into a sequence of invisible glyphs that shift text left or right.static StringgetOffsetMinimessage(int pixelOffset) Converts a pixel offset into a MiniMessage string containing invisible glyphs.static voidInitializes the offset font provider and registers all necessary glyphs.
-
Constructor Details
-
TextOffset
public TextOffset()
-
-
Method Details
-
init
Initializes the offset font provider and registers all necessary glyphs.This method registers an "offset" font within the given namespace and creates texture glyphs that are moved far off-screen (-9000 height) to ensure invisibility.
- Parameters:
ns- TheNamespacecontext where the font and textures will be registered.
-
getOffset
public static net.kyori.adventure.text.Component getOffset(int pixelOffset) Converts a pixel offset into a sequence of invisible glyphs that shift text left or right.- Parameters:
pixelOffset- The number of pixels to offset the text (positive for right, negative for left).- Returns:
- A
Componentcontaining the invisible offset glyphs in the custom font.
-
getOffsetMinimessage
Converts a pixel offset into a MiniMessage string containing invisible glyphs.The method uses a greedy algorithm to decompose the target
pixelOffsetinto the fewest possible number of predefined glyph widths.- Parameters:
pixelOffset- The number of pixels to offset the text.- Returns:
- A MiniMessage-formatted
Stringusing theabyssallib:offsetfont.
-