Interface CharacterManager


public interface CharacterManager
Provides functionality for managing character information used for layout and formatting.

A CharacterManager allows you to register custom characters with specific widths, retrieve character information, remove characters, and align strings based on character widths.

This is particularly useful when handling text rendering or custom UI layouts where each character might have a different visual width.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CharacterInfo
    The default character information used when no specific info is found.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCharacter(char c, int length)
    Registers a custom character with its associated visual length.
    default void
    addCharacter(String string, int length)
    Registers a custom character from a string with its associated visual length.
    align(int limit, String string)
    Aligns a string based on a specified limit using character information.
    default String
    align(String string)
    Aligns a string based on a default width limit.
    getInfo(char c)
    Retrieves the CharacterInfo for the given character.
    getInfo(String string)
    Retrieves the CharacterInfo for the first character of the provided string.
    void
    Removes the specified characters from the manager.
    default void
    Removes characters specified by strings from the manager.
    static @Nullable Character
    Converts a string into a Character if it contains exactly one character.
  • Field Details

    • DEFAULT_INFO

      static final CharacterInfo DEFAULT_INFO
      The default character information used when no specific info is found. Defaults to the character 'a' with a base length of 5.
  • Method Details

    • getInfo

      CharacterInfo getInfo(char c)
      Retrieves the CharacterInfo for the given character.
      Parameters:
      c - the character for which to retrieve information
      Returns:
      the CharacterInfo corresponding to the character
    • getInfo

      default CharacterInfo getInfo(String string)
      Retrieves the CharacterInfo for the first character of the provided string.

      If the input string is null, empty, or contains more than one character, the default character information is returned.

      Parameters:
      string - the string representing the character (should be of length 1)
      Returns:
      the CharacterInfo for the character, or DEFAULT_INFO if invalid
    • addCharacter

      void addCharacter(char c, int length)
      Registers a custom character with its associated visual length.

      This allows the CharacterManager to handle custom formatting based on character widths.

      Parameters:
      c - the character to add
      length - the visual length (width) of the character
    • addCharacter

      default void addCharacter(String string, int length)
      Registers a custom character from a string with its associated visual length.

      The string should contain exactly one character; otherwise, the operation is ignored.

      Parameters:
      string - the string representing the character to add
      length - the visual length (width) of the character
    • removeCharacters

      void removeCharacters(Character... chars)
      Removes the specified characters from the manager.
      Parameters:
      chars - the characters to remove
    • removeCharacters

      default void removeCharacters(String... strings)
      Removes characters specified by strings from the manager.

      Each string should contain exactly one character; if not, it is ignored.

      Parameters:
      strings - an array of strings representing the characters to remove
    • align

      String align(int limit, String string)
      Aligns a string based on a specified limit using character information.

      This method adjusts the string's layout so that it fits within a given visual width (limit), using the character lengths defined in the manager.

      Parameters:
      limit - the maximum allowed width for the string
      string - the string to be aligned
      Returns:
      the aligned string
    • align

      default String align(String string)
      Aligns a string based on a default width limit.

      The default limit is set to 154. This method provides a convenient overload if no custom limit is required.

      Parameters:
      string - the string to be aligned
      Returns:
      the aligned string using the default width limit
    • toCharacter

      @Nullable static @Nullable Character toCharacter(String string)
      Converts a string into a Character if it contains exactly one character.

      If the input string is blank or contains more than one character, null is returned.

      Parameters:
      string - the string to convert
      Returns:
      the Character if the string is valid; otherwise, null