TextParams

Encapsulates all parameters for rendering text as an image.

The TextParams class defines the configuration needed to generate a bitmap of text. It includes options for:

  • Content and Styling: The text content, its size, color, and font properties (custom font, weight, and style).

  • Dimensions: Explicit width/height as well as maximum allowed width/height. If explicit dimensions are not provided, the layout is computed based on the text content and padding.

  • Layout and Spacing: Padding around the text, additional line spacing, text alignment, and the maximum number of lines to render.

  • Borders and Background: Border width, border color, corner radius for the border, transparency flag, and an optional background color.

You can conveniently configure these properties using the fluent setter methods.

Important Notes:

  • Not all fonts support every combination of weight and style. In such cases, the system may substitute or approximate the requested configuration.

  • If a custom font is specified via setCustomFont, ensure that the asset path provided (e.g., "fonts/CustomFont.ttf") is correct and that the font file exists in the assets folder.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

An optional background color for the text image. If set, it overrides transparency.

Link copied to clipboard

The color of the border.

Link copied to clipboard

The corner radius for the border.

Link copied to clipboard

The width of the border drawn around the text image.

Link copied to clipboard

An optional custom font (FontFamily) to use for rendering the text.

Link copied to clipboard

The desired text size (typically in pixels or scaled pixels).

Link copied to clipboard

The style of the font (e.g., italic, normal).

Link copied to clipboard

The weight of the font.

Link copied to clipboard
var height: Int?

Optional explicit height for the image; if not provided, maxHeight is used.

Link copied to clipboard

A flag indicating whether the image background should be transparent.

Link copied to clipboard

Additional spacing between lines of text.

Link copied to clipboard

The maximum height allowed for the text layout.

Link copied to clipboard

The maximum number of lines to render before truncation.

Link copied to clipboard

The maximum width allowed for the text layout.

Link copied to clipboard

The padding to apply around the text.

Link copied to clipboard

The text content to be rendered.

Link copied to clipboard

The alignment of the text (e.g., center, left, right).

Link copied to clipboard

The color of the text.

Link copied to clipboard
var width: Int?

Optional explicit width for the image; if not provided, maxWidth is used.

Functions

Link copied to clipboard

Sets the text alignment.

Link copied to clipboard

Sets the background color for the image.

Link copied to clipboard

Sets the color of the border.

Link copied to clipboard

Sets the corner radius for the border.

Link copied to clipboard

Sets the width of the border drawn around the text image.

Link copied to clipboard

Sets a custom font to be used when rendering the text.

Link copied to clipboard

Sets the style for the font (e.g., italic, normal).

Link copied to clipboard

Sets the weight for the font.

Link copied to clipboard
fun setHeight(height: Int): TextParams

Sets the explicit height for the text layout.

Link copied to clipboard

Sets the line spacing for the text.

Link copied to clipboard
fun setMaxHeight(maxHeight: Int): TextParams

Sets the maximum height for the text layout.

Link copied to clipboard

Sets the maximum number of lines for the text.

Link copied to clipboard
fun setMaxWidth(maxWidth: Int): TextParams

Sets the maximum width for the text layout.

Link copied to clipboard
fun setPadding(padding: Float): TextParams

Sets the padding for the text layout.

Link copied to clipboard

Sets the text content.

Link copied to clipboard

Sets the text color.

Link copied to clipboard

Sets the text size.

Link copied to clipboard
fun setTransparent(isTransparent: Boolean): TextParams

Sets the transparency flag for the image.

Link copied to clipboard
fun setWidth(width: Int): TextParams

Sets the explicit width for the text layout.

Link copied to clipboard

Calculates the total padding for the layout.