text

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 22 Imported by: 0

README

Foundation Text

Gio Implementation

Kotlin source

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/BasicText.kt;l=92?q=file:androidx%2Fcompose%2Ffoundation%2Ftext%2FBasicText.kt%20function:BasicText

/**
 * Basic element that displays text and provides semantics / accessibility information. Typically
 * you will instead want to use [androidx.compose.material.Text], which is a higher level Text
 * element that contains semantics and consumes style information from a theme.
 *
 * @param text The text to be displayed.
 * @param modifier [Modifier] to apply to this layout node.
 * @param style Style configuration for the text such as color, font, line height etc.
 * @param onTextLayout Callback that is executed when a new text layout is calculated. A
 *   [TextLayoutResult] object that callback provides contains paragraph information, size of the
 *   text, baselines and other details. The callback can be used to add additional decoration or
 *   functionality to the text. For example, to draw selection around the text.
 * @param overflow How visual overflow should be handled.
 * @param softWrap Whether the text should break at soft line breaks. If false, the glyphs in the
 *   text will be positioned as if there was unlimited horizontal space. If [softWrap] is false,
 *   [overflow] and TextAlign may have unexpected effects.
 * @param maxLines An optional maximum number of lines for the text to span, wrapping if necessary.
 *   If the text exceeds the given number of lines, it will be truncated according to [overflow] and
 *   [softWrap]. It is required that 1 <= [minLines] <= [maxLines].
 * @param minLines The minimum height in terms of minimum number of visible lines. It is required
 *   that 1 <= [minLines] <= [maxLines].
 * @param color Overrides the text color provided in [style]
 * @param autoSize Enable auto sizing for this text composable. Finds the biggest font size that
 *   fits in the available space and lays the text out with this size. This performs multiple layout
 *   passes and can be slower than using a fixed font size. This takes precedence over sizes defined
 *   through [style]. See [TextAutoSize] and
 *   [androidx.compose.foundation.samples.TextAutoSizeBasicTextSample].
 */
@Composable
fun BasicText(
    text: String,
    modifier: Modifier = Modifier,
    style: TextStyle = TextStyle.Default,
    onTextLayout: ((TextLayoutResult) -> Unit)? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    softWrap: Boolean = true,
    maxLines: Int = Int.MAX_VALUE,
    minLines: Int = 1,
    color: ColorProducer? = null,
    autoSize: TextAutoSize? = null,
)

Documentation

Index

Constants

View Source
const BasicTextNodeID = "BasicText"
View Source
const INLINE_CONTENT_TAG = "compose.foundation.text.inlineContent"

* The annotation tag used by inline content.

View Source
const REPLACEMENT_CHAR = "\uFFFD"

A string that contains a replacement character specified by unicode. It's used as the default value of alternate text.

Variables

View Source
var TextAutoSizeDefaults = TextAutoSizeValues{
	MinFontSize: uiTextUnitSp(12),
	MaxFontSize: uiTextUnitSp(112),
	StepSize:    uiTextUnitSp(0.25),
}

TextAutoSizeDefaults contains defaults for TextAutoSize APIs.

Functions

This section is empty.

Types

type Alignment

type Alignment = text.Alignment
const (
	Start  Alignment = text.Start
	End    Alignment = text.End
	Middle Alignment = text.Middle
)

type BasicTextConstructorArgs

type BasicTextConstructorArgs struct {
	// contains filtered or unexported fields
}

type Composable

type Composable = api.Composable

func BasicText

func BasicText(
	annotatedString text.AnnotatedString,
	options ...TextOption,
) Composable

func Text

func Text(value string, options ...TextOption) Composable

Text renders a text leaf. The value is stored in a slot for tooling.

type Composer

type Composer = api.Composer

type InlineTextContent

type InlineTextContent struct {
	/**
	 * The setting object that defines the size and vertical alignment of this composable in the
	 * text line. This is different from the measure of Layout
	 *
	 * @see Placeholder
	 */
	PlaceHolder uiPlaceholder
	/**
	 * The composable to be inserted into the text layout. The string parameter passed to it will
	 * the alternateText given to [appendInlineContent].
	 */
	Children []func(string) Composable
}

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/InlineTextContent.kt;drc=4970f6e96cdb06089723da0ab8ec93ae3f067c7a;l=72

type TextAutoSize

type TextAutoSize interface {
	GetFontSize(scope TextAutoSizeLayoutScope, constraints uiConstraints, text uiAnnotatedString) uiTextUnit
}

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextAutoSize.kt;drc=4970f6e96cdb06089723da0ab8ec93ae3f067c7a;l=35

func NewStepBasedTextAutoSize

func NewStepBasedTextAutoSize(
	minFontSize uiTextUnit,
	maxFontSize uiTextUnit,
	stepSize uiTextUnit,
) TextAutoSize

NewStepBasedTextAutoSize automatically sizes the text with the biggest font size that fits the available space.

type TextAutoSizeLayoutScope

type TextAutoSizeLayoutScope interface {
	PerformLayout(constraints uiConstraints, text uiAnnotatedString, fontSize uiTextUnit) uiTextLayoutResult
}

type TextAutoSizeValues

type TextAutoSizeValues struct {
	MinFontSize uiTextUnit
	MaxFontSize uiTextUnit
	StepSize    uiTextUnit
}

type TextOption

type TextOption func(*TextOptions)

func WithAutoSize

func WithAutoSize(autoSize TextAutoSize) TextOption

func WithColor

func WithColor(color graphics.Color) TextOption

func WithMaxLines

func WithMaxLines(maxLines int) TextOption

func WithMinLines

func WithMinLines(minLines int) TextOption

func WithModifier

func WithModifier(m ui.Modifier) TextOption

func WithOnTextLayout

func WithOnTextLayout(onTextLayout func(text.TextLayoutResult)) TextOption

func WithOverFlow

func WithOverFlow(overFlow style.TextOverFlow) TextOption

func WithSoftWrap

func WithSoftWrap(softWrap bool) TextOption

func WithTextStyle

func WithTextStyle(ts *text.TextStyle) TextOption

type TextOptions

type TextOptions struct {
	Modifier ui.Modifier

	TextStyle *text.TextStyle

	OnTextLayout func(text.TextLayoutResult)
	OverFlow     style.TextOverFlow
	SoftWrap     bool

	MaxLines int
	MinLines int

	InlineContent map[string]InlineTextContent

	Color    graphics.Color
	AutoSize TextAutoSize
}

func DefaultTextOptions

func DefaultTextOptions() TextOptions

type TextStyle

type TextStyle = text.TextStyle

type WrapPolicy

type WrapPolicy = text.WrapPolicy

WrapPolicy configures strategies for choosing where to break lines of text for line wrapping.

const (
	// WrapHeuristically tries to minimize breaking within words (UAX#14 text segments)
	// while also ensuring that text fits within the given MaxWidth. It will only break
	// a line within a word (on a UAX#29 grapheme cluster boundary) when that word cannot
	// fit on a line by itself. Additionally, when the final word of a line is being
	// truncated, this policy will preserve as many symbols of that word as
	// possible before the truncator.
	WrapHeuristically WrapPolicy = text.WrapHeuristically
	// WrapWords does not permit words (UAX#14 text segments) to be broken across lines.
	// This means that sometimes long words will exceed the MaxWidth they are wrapped with.
	WrapWords WrapPolicy = text.WrapWords
	// WrapGraphemes will maximize the amount of text on each line at the expense of readability,
	// breaking any word across lines on UAX#29 grapheme cluster boundaries to maximize the number of
	// grapheme clusters on each line.
	WrapGraphemes WrapPolicy = text.WrapGraphemes
)

Directories

Path Synopsis
Package input provides text field state management and editing infrastructure.
Package input provides text field state management and editing infrastructure.
internal
Package internal provides internal implementation details for text input.
Package internal provides internal implementation details for text input.
internal/selection
Package selection provides selection state management for text fields.
Package selection provides selection state management for text fields.
internal/undo
Package undo provides undo/redo infrastructure for text editing.
Package undo provides undo/redo infrastructure for text editing.
Package modifiers provides text modifier implementations for foundation text components.
Package modifiers provides text modifier implementations for foundation text components.
Package selection provides text selection functionality for Compose Foundation.
Package selection provides text selection functionality for Compose Foundation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL