TextKt

Added in 1.3.0-alpha06

public final class TextKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.Text
basicText(
    @NonNull LayoutString text,
    LayoutElementBuilders.FontStyle fontStyle,
    LayoutModifier modifier,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @Dimension(unit = 2) float lineHeight
)

Builds a text string.

static final @NonNull LayoutElementBuilders.FontStyle
fontStyle(
    @Dimension(unit = 2) float size,
    boolean italic,
    boolean underline,
    LayoutColor color,
    int weight,
    float letterSpacingEm,
    @RequiresSchemaVersion(major = 1, minor = 300) @NonNull List<@NonNull Float> additionalSizesSp,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull String> preferredFontFamilies
)

Builds the styling of a font (e.g. font size, and metrics).

Public methods

public static final @NonNull LayoutElementBuilders.Text basicText(
    @NonNull LayoutString text,
    LayoutElementBuilders.FontStyle fontStyle,
    LayoutModifier modifier,
    int maxLines,
    int multilineAlignment,
    int overflow,
    @Dimension(unit = 2) float lineHeight
)

Builds a text string.

Parameters
@NonNull LayoutString text

The text to render.

LayoutElementBuilders.FontStyle fontStyle

The style of font to use (size, bold etc). If not specified, defaults to the platform's default body font.

LayoutModifier modifier

Modifiers to set to this element..

int maxLines

The maximum number of lines that can be represented by the Text element. If not defined, the Text element will be treated as a single-line element.

int multilineAlignment

Alignment of the text within its bounds. Note that a Text element will size itself to wrap its contents, so this option is meaningless for single-line text (for that, use alignment of the outer container). For multi-line text, however, this will set the alignment of lines relative to the Text element bounds. If not defined, defaults to TEXT_ALIGN_CENTER.

int overflow

How to handle text which overflows the bound of the Text element. A Text element will grow as large as possible inside its parent container (while still respecting max_lines); if it cannot grow large enough to render all of its text, the text which cannot fit inside its container will be truncated. If not defined, defaults to TEXT_OVERFLOW_TRUNCATE.

@Dimension(unit = 2) float lineHeight

The explicit height between lines of text. This is equivalent to the vertical distance between subsequent baselines. If not specified, defaults the font's recommended interline spacing.

public static final @NonNull LayoutElementBuilders.FontStyle fontStyle(
    @Dimension(unit = 2) float size,
    boolean italic,
    boolean underline,
    LayoutColor color,
    int weight,
    float letterSpacingEm,
    @RequiresSchemaVersion(major = 1, minor = 300) @NonNull List<@NonNull Float> additionalSizesSp,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull String> preferredFontFamilies
)

Builds the styling of a font (e.g. font size, and metrics).

Parameters
@Dimension(unit = 2) float size

The size of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font.

boolean italic

Whether the text should be rendered in a italic typeface.

boolean underline

Whether the text should be rendered with an underline.

LayoutColor color

The text color. If not defined, defaults to white.

int weight

The weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal".

float letterSpacingEm

The text letter-spacing. Positive numbers increase the space between letters while negative numbers tighten the space. If not specified, defaults to 0.

@RequiresSchemaVersion(major = 1, minor = 300) @NonNull List<@NonNull Float> additionalSizesSp

when this FontStyle is applied to a Text element with static text, the text size will be automatically picked from the provided sizes to try to perfectly fit within its parent bounds. In other words, the largest size from the specified preset sizes that can fit the most text within the parent bounds will be used.

@RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings

The collection of font settings to be applied. If more than one Setting with the same axis tag is specified, the first one will be used. Supported settings depend on the font used and renderer version.

@RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull String> preferredFontFamilies

is the ordered list of font families to pick from for this FontStyle. If the given font family is not available on a device, the fallback values will be attempted to use, in order in which they are given. Note that support for font family customization is dependent on the target platform.