Interface HudMetrics


public interface HudMetrics
Pixel measurement against a HUD's real fonts.

Element keys come from build/manifest.json, which the engine writes on every compile. They read as <layout>_text_<n>, numbered in the order the layout declares its texts.

Useful because a HUD's text is rasterised at a specific size from specific glyphs, so its width has nothing to do with character count. Wrapping a quest description by counting characters gives ragged lines; wrapping it with these gives the lines the player will actually see.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    width(String hudKey, String elementKey, String text)
    Width of a string in HUD pixels.
    wrap(String hudKey, String elementKey, String text, int maxWidthPx)
    Wraps text to a pixel width.
  • Method Details

    • width

      int width(String hudKey, String elementKey, String text)
      Width of a string in HUD pixels.
      Throws:
      IllegalArgumentException - if the element does not exist or is not a text element
    • wrap

      List<String> wrap(String hudKey, String elementKey, String text, int maxWidthPx)
      Wraps text to a pixel width. Existing newlines are honoured, and a word too long for a whole line is broken by character rather than left to overflow.
      Throws:
      IllegalArgumentException - if the element does not exist or is not a text element