Skip to content

getTextSize

fun getTextSize(
    text: Component, 
    scale: Float = 1.0f, 
    font: Font = Minecraft.getInstance().font
): Size

Returns the rendered pixel size (width × height) of text at the given scale.

Useful for sizing containers to exactly fit their text content before composition.

Parameters

  • text: The Component whose rendered dimensions are measured.

  • scale: Font scale factor (1.0 = native size).

  • font: The Font to measure with; defaults to Minecraft's standard font.