androidx.wear.protolayout.layout


Top-level functions summary

LayoutElementBuilders.Text
basicText(
    text: LayoutString,
    fontStyle: LayoutElementBuilders.FontStyle?,
    modifier: LayoutModifier?,
    maxLines: Int,
    multilineAlignment: Int,
    overflow: Int,
    lineHeight: @Dimension(unit = 2) Float
)

Builds a text string.

LayoutElementBuilders.FontStyle
fontStyle(
    size: @Dimension(unit = 2) Float,
    italic: Boolean,
    underline: Boolean,
    color: LayoutColor?,
    weight: Int,
    letterSpacingEm: Float,
    @RequiresSchemaVersion(major = 1, minor = 300) additionalSizesSp: List<Float>,
    @RequiresSchemaVersion(major = 1, minor = 400) settings: List<LayoutElementBuilders.FontSetting>,
    @RequiresSchemaVersion(major = 1, minor = 400) preferredFontFamilies: List<String>
)

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

Top-level functions

fun basicText(
    text: LayoutString,
    fontStyle: LayoutElementBuilders.FontStyle? = null,
    modifier: LayoutModifier? = null,
    maxLines: Int = 0,
    multilineAlignment: Int = TEXT_ALIGN_UNDEFINED,
    overflow: Int = TEXT_OVERFLOW_UNDEFINED,
    lineHeight: @Dimension(unit = 2) Float = Float.NaN
): LayoutElementBuilders.Text

Builds a text string.

Parameters
text: LayoutString

The text to render.

fontStyle: LayoutElementBuilders.FontStyle? = null

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

modifier: LayoutModifier? = null

Modifiers to set to this element..

maxLines: Int = 0

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.

multilineAlignment: Int = TEXT_ALIGN_UNDEFINED

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.

overflow: Int = TEXT_OVERFLOW_UNDEFINED

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.

lineHeight: @Dimension(unit = 2) Float = Float.NaN

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.

fun fontStyle(
    size: @Dimension(unit = 2) Float = 0.0f,
    italic: Boolean = false,
    underline: Boolean = false,
    color: LayoutColor? = null,
    weight: Int = FONT_WEIGHT_UNDEFINED,
    letterSpacingEm: Float = Float.NaN,
    @RequiresSchemaVersion(major = 1, minor = 300) additionalSizesSp: List<Float> = listOf(),
    @RequiresSchemaVersion(major = 1, minor = 400) settings: List<LayoutElementBuilders.FontSetting> = listOf(),
    @RequiresSchemaVersion(major = 1, minor = 400) preferredFontFamilies: List<String> = listOf()
): LayoutElementBuilders.FontStyle

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

Parameters
size: @Dimension(unit = 2) Float = 0.0f

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

italic: Boolean = false

Whether the text should be rendered in a italic typeface.

underline: Boolean = false

Whether the text should be rendered with an underline.

color: LayoutColor? = null

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

weight: Int = FONT_WEIGHT_UNDEFINED

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".

letterSpacingEm: Float = Float.NaN

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) additionalSizesSp: List<Float> = listOf()

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) settings: List<LayoutElementBuilders.FontSetting> = listOf()

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) preferredFontFamilies: List<String> = listOf()

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.