text

package
v0.1.93 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package text provides rich text styling and annotation capabilities.

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackgroundColor = graphics.ColorTransparent
View Source
var DefaultColor = graphics.ColorBlack
View Source
var DefaultColorForegroundStyle = style.TextForegroundStyleFromColor(DefaultColor)
View Source
var DefaultFontSize = unit.Sp(14)
View Source
var DefaultHyphens = style.HyphensNone
View Source
var DefaultLetterSpacing = unit.Sp(0)
View Source
var DefaultLineBreak = style.LineBreakParagraph
View Source
var DefaultLineHeight = unit.TextUnitUnspecified // TODO: Should this stay unspecified ?
View Source
var DefaultTextAlign = style.TextAlignStart
View Source
var DefaultTextIndent = style.TextIndentNone
View Source
var DefaultTextMotion = style.TextMotionStatic
View Source
var TextRangeZero = TextRange{Start: 0, End: 0}

TextRangeZero is a TextRange with both start and end at 0.

Functions

func EqualParagraphStyle

func EqualParagraphStyle(a, b *ParagraphStyle) bool

func EqualPlatformParagraphStyle

func EqualPlatformParagraphStyle(a, b *PlatformParagraphStyle) bool

func EqualPlatformSpanStyle

func EqualPlatformSpanStyle(a, b *PlatformSpanStyle) bool

func EqualPlatformTextStyle

func EqualPlatformTextStyle(a, b *PlatformTextStyle) bool

func EqualSpanStyle

func EqualSpanStyle(a, b *SpanStyle) bool

func EqualTextStyle

func EqualTextStyle(a, b *TextStyle) bool

func IsSpecifiedParagraphStyle

func IsSpecifiedParagraphStyle(s *ParagraphStyle) bool

func IsSpecifiedPlatformParagraphStyle

func IsSpecifiedPlatformParagraphStyle(s *PlatformParagraphStyle) bool

func IsSpecifiedPlatformSpanStyle

func IsSpecifiedPlatformSpanStyle(s *PlatformSpanStyle) bool

func IsSpecifiedPlatformTextStyle

func IsSpecifiedPlatformTextStyle(s *PlatformTextStyle) bool

func IsSpecifiedSpanStyle

func IsSpecifiedSpanStyle(s *SpanStyle) bool

func IsSpecifiedTextStyle

func IsSpecifiedTextStyle(style *TextStyle) bool

func MapEachParagraphStyle

func MapEachParagraphStyle[T any](
	as AnnotatedString,
	defaultParagraphStyle ParagraphStyle,
	block func(annotatedString AnnotatedString, paragraphStyle Range[ParagraphStyle]) T,
) []T

MapEachParagraphStyle iterates normalized paragraph styles.

func SameParagraphStyle

func SameParagraphStyle(a, b *ParagraphStyle) bool

Identity (2 ns)

func SameSpanStyle

func SameSpanStyle(a, b *SpanStyle) bool

Identity (2 ns)

func SameTextStyle

func SameTextStyle(a, b *TextStyle) bool

Identity (2 ns)

func SemanticEqualParagraphStyle

func SemanticEqualParagraphStyle(a, b *ParagraphStyle) bool

Semantic equality (field-by-field, 20 ns)

func SemanticEqualSpanStyle

func SemanticEqualSpanStyle(a, b *SpanStyle) bool

Semantic equality (field-by-field, 20 ns)

func SemanticEqualTextStyle

func SemanticEqualTextStyle(a, b *TextStyle) bool

Semantic equality (field-by-field, 20 ns)

func StringParagraphStyle

func StringParagraphStyle(s *ParagraphStyle) string

func StringPlatformParagraphStyle

func StringPlatformParagraphStyle(s *PlatformParagraphStyle) string

func StringSpanStyle

func StringSpanStyle(s *SpanStyle) string

Types

type AnnotatedString

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

AnnotatedString is immutable text with style and metadata annotations. Use Builder to construct instances efficiently.

func Empty

func Empty() AnnotatedString

Empty returns an empty AnnotatedString.

func NewAnnotatedString

func NewAnnotatedString(text string, spanStyles []Range[SpanStyle], paragraphStyles []Range[ParagraphStyle]) AnnotatedString

NewAnnotatedString creates an AnnotatedString from text and optional style ranges.

func (AnnotatedString) Append

Append concatenates another AnnotatedString.

func (AnnotatedString) Capitalize

func (as AnnotatedString) Capitalize() AnnotatedString

Capitalize returns a new AnnotatedString with the first character capitalized.

func (AnnotatedString) CharAt

func (as AnnotatedString) CharAt(index int) byte

CharAt returns the byte at index (useful for ASCII).

func (AnnotatedString) Decapitalize

func (as AnnotatedString) Decapitalize() AnnotatedString

Decapitalize returns a new AnnotatedString with the first character lowercased.

func (AnnotatedString) FlatMapAnnotations

func (as AnnotatedString) FlatMapAnnotations(transform func(Range[Annotation]) []Range[Annotation]) AnnotatedString

FlatMapAnnotations returns a new AnnotatedString with annotations transformed to multiple annotations.

func (AnnotatedString) GetLinkAnnotations

func (as AnnotatedString) GetLinkAnnotations(start, end int) []Range[LinkAnnotation]

GetLinkAnnotations queries LinkAnnotations within [start, end).

func (AnnotatedString) GetLocalAnnotations

func (as AnnotatedString) GetLocalAnnotations(start, end int, predicate func(Annotation) bool) []Range[Annotation]

GetLocalAnnotations finds annotations in range matching predicate and converts to local range.

func (AnnotatedString) GetLocalParagraphStyles

func (as AnnotatedString) GetLocalParagraphStyles(start, end int) []Range[ParagraphStyle]

GetLocalParagraphStyles finds ParagraphStyles in range and converts them to local range.

func (AnnotatedString) GetStringAnnotations

func (as AnnotatedString) GetStringAnnotations(tag string, start, end int) []Range[string]

GetStringAnnotations queries string annotations by tag within [start, end).

func (AnnotatedString) HasEqualAnnotations

func (as AnnotatedString) HasEqualAnnotations(other AnnotatedString) bool

HasEqualAnnotations compares annotation lists for deep equality.

func (AnnotatedString) HasInlineContent

func (as AnnotatedString) HasInlineContent() bool

func (AnnotatedString) HasLinkAnnotations

func (as AnnotatedString) HasLinkAnnotations(start, end int) bool

HasLinkAnnotations checks if any link annotations exist in range.

func (as AnnotatedString) HasLinks() bool

func (AnnotatedString) HasStringAnnotations

func (as AnnotatedString) HasStringAnnotations(tag string, start, end int) bool

HasStringAnnotations checks if any string annotations with tag exist in range.

func (AnnotatedString) Len

func (as AnnotatedString) Len() int

Len returns the length of the text.

func (AnnotatedString) MapAnnotations

func (as AnnotatedString) MapAnnotations(transform func(Range[Annotation]) Range[Annotation]) AnnotatedString

MapAnnotations returns a new AnnotatedString with annotations transformed.

func (AnnotatedString) NormalizedParagraphStyles

func (as AnnotatedString) NormalizedParagraphStyles(defaultParagraphStyle ParagraphStyle) []Range[ParagraphStyle]

NormalizedParagraphStyles determines the paragraph boundaries and merges styles. It handles gaps (using defaultParagraphStyle) and nested paragraphs.

func (AnnotatedString) ParagraphStyles

func (as AnnotatedString) ParagraphStyles() []Range[ParagraphStyle]

ParagraphStyles returns all ParagraphStyle ranges (may be empty slice).

func (AnnotatedString) SpanStyles

func (as AnnotatedString) SpanStyles() []Range[SpanStyle]

SpanStyles returns all SpanStyle ranges (may be empty slice).

func (AnnotatedString) String

func (as AnnotatedString) String() string

String returns the plain text (implements fmt.Stringer).

func (AnnotatedString) SubSequence

func (as AnnotatedString) SubSequence(start, end int) AnnotatedString

SubSequence returns a substring with annotations in range [start, end).

func (AnnotatedString) SubstringWithoutParagraphStyles

func (as AnnotatedString) SubstringWithoutParagraphStyles(start, end int) AnnotatedString

SubstringWithoutParagraphStyles returns a substring without paragraph styles.

func (AnnotatedString) Text

func (as AnnotatedString) Text() string

Text returns the plain text.

func (AnnotatedString) ToLower

func (as AnnotatedString) ToLower() AnnotatedString

ToLower returns a new AnnotatedString with text converted to lowercase.

func (AnnotatedString) ToUpper

func (as AnnotatedString) ToUpper() AnnotatedString

ToUpper returns a new AnnotatedString with text converted to uppercase.

type Annotation

type Annotation interface {
	// contains filtered or unexported methods
}

Annotation is a marker interface for all annotation types.

type Builder

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

Builder constructs AnnotatedString instances.

func NewBuilder

func NewBuilder(capacity ...int) *Builder

NewBuilder creates a Builder with optional initial capacity.

func NewBuilderFromAnnotatedString

func NewBuilderFromAnnotatedString(as AnnotatedString) *Builder

NewBuilderFromAnnotatedString creates a Builder initialized with the given AnnotatedString.

func (*Builder) AddBullet

func (b *Builder) AddBullet(bullet Bullet, start, end int)

AddBullet adds a Bullet annotation to range [start, end).

func (b *Builder) AddLink(link LinkAnnotation, start, end int)

AddLink adds a LinkAnnotation to range [start, end).

func (*Builder) AddParagraphStyle

func (b *Builder) AddParagraphStyle(style ParagraphStyle, start, end int)

AddParagraphStyle adds a ParagraphStyle to range [start, end).

func (*Builder) AddStringAnnotation

func (b *Builder) AddStringAnnotation(tag, annotation string, start, end int)

AddStringAnnotation adds a string annotation with a tag.

func (*Builder) AddStyle

func (b *Builder) AddStyle(style SpanStyle, start, end int)

AddStyle adds a SpanStyle to range [start, end).

func (*Builder) AddTtsAnnotation

func (b *Builder) AddTtsAnnotation(tts TtsAnnotation, start, end int)

AddTtsAnnotation adds a TtsAnnotation to range [start, end).

func (*Builder) Append

func (b *Builder) Append(s string)

Append adds plain text.

func (*Builder) AppendAnnotatedString

func (b *Builder) AppendAnnotatedString(as AnnotatedString)

AppendAnnotatedString adds another AnnotatedString with offset annotations.

func (*Builder) FlatMapAnnotations

func (b *Builder) FlatMapAnnotations(transform func(Range[Annotation]) []Range[Annotation])

FlatMapAnnotations transforms annotations into multiple annotations.

func (*Builder) Len

func (b *Builder) Len() int

Len returns current text length.

func (*Builder) MapAnnotations

func (b *Builder) MapAnnotations(transform func(Range[Annotation]) Range[Annotation])

MapAnnotations transforms annotations in the builder.

func (*Builder) Pop

func (b *Builder) Pop()

Pop ends the last pushed style/annotation.

func (*Builder) PopTo

func (b *Builder) PopTo(index int)

PopTo pops all styles up to and including the given index.

func (*Builder) PushBullet

func (b *Builder) PushBullet(bullet Bullet) int

PushBullet pushes a Bullet annotation onto the stack.

func (b *Builder) PushLink(link LinkAnnotation) int

PushLink pushes a LinkAnnotation onto the stack.

func (*Builder) PushParagraphStyle

func (b *Builder) PushParagraphStyle(style ParagraphStyle) int

PushParagraphStyle pushes a ParagraphStyle onto the stack.

func (*Builder) PushStringAnnotation

func (b *Builder) PushStringAnnotation(tag, annotation string) int

PushStringAnnotation pushes a string annotation onto the stack.

func (*Builder) PushStyle

func (b *Builder) PushStyle(style SpanStyle) int

PushStyle pushes a SpanStyle onto the stack for subsequent text.

func (*Builder) PushTtsAnnotation

func (b *Builder) PushTtsAnnotation(tts TtsAnnotation) int

PushTtsAnnotation pushes a TtsAnnotation onto the stack.

func (*Builder) ToAnnotatedString

func (b *Builder) ToAnnotatedString() AnnotatedString

ToAnnotatedString builds the final immutable AnnotatedString.

func (*Builder) WithAnnotation

func (b *Builder) WithAnnotation(tag, annotation string, block func())

WithAnnotation pushes annotation, executes block, and pops.

func (*Builder) WithBulletList

func (b *Builder) WithBulletList(
	indentation unit.TextUnit,
	bullet Bullet,
	block func(*BulletScope),
)

WithBulletList creates a bullet list scope.

func (b *Builder) WithLink(link LinkAnnotation, block func())

WithLink pushes link annotation, executes block, and pops.

func (*Builder) WithParagraphStyle

func (b *Builder) WithParagraphStyle(style ParagraphStyle, block func())

WithParagraphStyle pushes paragraph style, executes block, and pops.

func (*Builder) WithStyle

func (b *Builder) WithStyle(style SpanStyle, block func())

WithStyle pushes style, executes block, and pops.

func (*Builder) WithTtsAnnotation

func (b *Builder) WithTtsAnnotation(tts TtsAnnotation, block func())

WithTtsAnnotation pushes tts annotation, executes block, and pops.

type Bullet

type Bullet struct {
}

Bullet represents a bullet list marker.

type BulletScope

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

BulletScope is the scope for a bullet list.

func (*BulletScope) WithBulletListItem

func (s *BulletScope) WithBulletListItem(
	bullet *Bullet,
	block func(),
)

WithBulletListItem adds a bullet list item.

type LinkAnnotation

type LinkAnnotation struct {
	URL string
}

LinkAnnotation marks clickable links in text.

type MultiParagraph

type MultiParagraph interface {
	// LineCount returns the number of lines in the text layout.
	LineCount() int

	// IsLineEllipsized returns true if the given line is ellipsized.
	IsLineEllipsized(lineIndex int) bool

	// DidExceedMaxLines returns true if the text exceeded the maximum number of lines.
	DidExceedMaxLines() bool

	// FirstBaseline returns the distance from the top to the alphabetic baseline of the first line.
	FirstBaseline() float32

	// LastBaseline returns the distance from the top to the alphabetic baseline of the last line.
	LastBaseline() float32

	// Height returns the total height of the text layout.
	Height() float32

	// Width returns the total width of the text layout.
	Width() float32

	// PlaceholderRects returns bounding boxes for placeholders.
	PlaceholderRects() []*geometry.Rect

	// GetLineStart returns the start offset of the given line, inclusive.
	GetLineStart(lineIndex int) int

	// GetLineEnd returns the end offset of the given line.
	// If visibleEnd is true, trailing whitespaces are not counted.
	GetLineEnd(lineIndex int, visibleEnd bool) int

	// GetLineTop returns the top y coordinate of the given line.
	GetLineTop(lineIndex int) float32

	// GetLineBaseline returns the baseline y coordinate of the given line.
	GetLineBaseline(lineIndex int) float32

	// GetLineBottom returns the bottom y coordinate of the given line.
	GetLineBottom(lineIndex int) float32

	// GetLineLeft returns the left x coordinate of the given line.
	GetLineLeft(lineIndex int) float32

	// GetLineRight returns the right x coordinate of the given line.
	GetLineRight(lineIndex int) float32

	// GetLineForOffset returns the line number for the specified text offset.
	GetLineForOffset(offset int) int

	// GetLineForVerticalPosition returns the line number closest to the given vertical position.
	GetLineForVerticalPosition(vertical float32) int

	// GetHorizontalPosition returns the horizontal position for the specified text offset.
	GetHorizontalPosition(offset int, usePrimaryDirection bool) float32

	// GetParagraphDirection returns the text direction of the paragraph containing the offset.
	GetParagraphDirection(offset int) style.ResolvedTextDirection

	// GetBidiRunDirection returns the text direction of the BiDi run at the offset.
	GetBidiRunDirection(offset int) style.ResolvedTextDirection

	// GetOffsetForPosition returns the character offset closest to the given graphical position.
	GetOffsetForPosition(position geometry.Offset) int

	// GetBoundingBox returns the bounding box of the character at the given offset.
	GetBoundingBox(offset int) geometry.Rect

	// GetWordBoundary returns the text range of the word at the given offset.
	GetWordBoundary(offset int) TextRange

	// GetCursorRect returns the rectangle of the cursor area at the given offset.
	GetCursorRect(offset int) geometry.Rect

	// GetPathForRange returns a path that encloses the given text range.
	GetPathForRange(start, end int) graphics.Path
}

MultiParagraph is the interface for multi-paragraph text layout.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/MultiParagraph.kt

type ParagraphStyle

type ParagraphStyle struct {
	TextAlign       style.TextAlign
	TextDirection   style.TextDirection
	LineHeight      unit.TextUnit
	TextIndent      *style.TextIndent
	PlatformStyle   *PlatformParagraphStyle
	LineHeightStyle *style.LineHeightStyle
	LineBreak       style.LineBreak
	Hyphens         style.Hyphens
	TextMotion      *style.TextMotion
}

ParagraphStyle configuration for a paragraph.

var ParagraphStyleUnspecified *ParagraphStyle = &ParagraphStyle{
	TextAlign:       style.TextAlignUnspecified,
	TextDirection:   style.TextDirectionUnspecified,
	LineHeight:      unit.TextUnitUnspecified,
	TextIndent:      nil,
	LineHeightStyle: nil,
	LineBreak:       style.LineBreakUnspecified,
	Hyphens:         style.HyphensUnspecified,
	TextMotion:      nil,
}

func CoalesceParagraphStyle

func CoalesceParagraphStyle(ptr, def *ParagraphStyle) *ParagraphStyle

func LerpParagraphStyle

func LerpParagraphStyle(start, stop *ParagraphStyle, fraction float32) *ParagraphStyle

LerpParagraphStyle interpolates between two ParagraphStyles.

func MergeParagraphStyle

func MergeParagraphStyle(a, b *ParagraphStyle) *ParagraphStyle

func ParagraphStyleResolveDefaults

func ParagraphStyleResolveDefaults(ps *ParagraphStyle, direction unit.LayoutDirection) *ParagraphStyle

func ResolveParagraphStyleDefaults

func ResolveParagraphStyleDefaults(s *ParagraphStyle, direction unit.LayoutDirection) *ParagraphStyle

func TakeOrElseParagraphStyle

func TakeOrElseParagraphStyle(s, def *ParagraphStyle) *ParagraphStyle

func (ParagraphStyle) Copy

type ParagraphStyleOption

type ParagraphStyleOption = func(*ParagraphStyleOptions)

func ParagraphStyleWithHyphens

func ParagraphStyleWithHyphens(hyphens style.Hyphens) ParagraphStyleOption

func ParagraphStyleWithLineBreak

func ParagraphStyleWithLineBreak(lineBreak style.LineBreak) ParagraphStyleOption

func ParagraphStyleWithLineHeight

func ParagraphStyleWithLineHeight(lineHeight unit.TextUnit) ParagraphStyleOption

func ParagraphStyleWithLineHeightStyle

func ParagraphStyleWithLineHeightStyle(lineHeightStyle *style.LineHeightStyle) ParagraphStyleOption

func ParagraphStyleWithPlatformStyle

func ParagraphStyleWithPlatformStyle(platformStyle *PlatformParagraphStyle) ParagraphStyleOption

func ParagraphStyleWithTextAlign

func ParagraphStyleWithTextAlign(textAlign style.TextAlign) ParagraphStyleOption

func ParagraphStyleWithTextDirection

func ParagraphStyleWithTextDirection(textDirection style.TextDirection) ParagraphStyleOption

func ParagraphStyleWithTextIndent

func ParagraphStyleWithTextIndent(textIndent *style.TextIndent) ParagraphStyleOption

func ParagraphStyleWithTextMotion

func ParagraphStyleWithTextMotion(textMotion *style.TextMotion) ParagraphStyleOption

type ParagraphStyleOptions

type ParagraphStyleOptions struct {
	TextAlign       style.TextAlign
	TextDirection   style.TextDirection
	LineHeight      unit.TextUnit
	TextIndent      *style.TextIndent
	PlatformStyle   *PlatformParagraphStyle
	LineHeightStyle *style.LineHeightStyle
	LineBreak       style.LineBreak
	Hyphens         style.Hyphens
	TextMotion      *style.TextMotion
}

type Placeholder

type Placeholder struct {
	// Width of the placeholder, must be specified in sp or em.
	Width unit.TextUnit

	// Height of the placeholder, must be specified in sp or em.
	Height unit.TextUnit

	// PlaceholderVerticalAlign specifies the vertical alignment of the placeholder within the text line.
	PlaceholderVerticalAlign PlaceholderVerticalAlign
}

Placeholder is a rectangle box inserted into text, which tells the text processor to leave an empty space. It is typically used to insert inline images, custom emojis, etc. into the text paragraph.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/Placeholder.kt

func NewPlaceholder

func NewPlaceholder(width, height unit.TextUnit, placeholderVerticalAlign PlaceholderVerticalAlign) Placeholder

NewPlaceholder creates a new Placeholder with validation. Panics if width or height is unspecified.

func (Placeholder) Copy

func (p Placeholder) Copy(width, height unit.TextUnit, placeholderVerticalAlign PlaceholderVerticalAlign) Placeholder

Copy creates a copy of the Placeholder with optional field overrides.

func (Placeholder) Equals

func (p Placeholder) Equals(other Placeholder) bool

Equals checks equality with another Placeholder.

func (Placeholder) String

func (p Placeholder) String() string

String returns a string representation of the Placeholder.

type PlaceholderVerticalAlign

type PlaceholderVerticalAlign int

PlaceholderVerticalAlign specifies how a placeholder is vertically aligned within a text line.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/Placeholder.kt

const (
	// PlaceholderVerticalAlignAboveBaseline aligns the bottom of the placeholder with the baseline.
	PlaceholderVerticalAlignAboveBaseline PlaceholderVerticalAlign = iota + 1

	// PlaceholderVerticalAlignTop aligns the top of the placeholder with the top of the entire line.
	PlaceholderVerticalAlignTop

	// PlaceholderVerticalAlignBottom aligns the bottom of the placeholder with the bottom of the entire line.
	PlaceholderVerticalAlignBottom

	// PlaceholderVerticalAlignCenter aligns the center of the placeholder with the center of the entire line.
	PlaceholderVerticalAlignCenter

	// PlaceholderVerticalAlignTextTop aligns the top of the placeholder with the top of the proceeding text.
	// Different from Top when there are texts with different font sizes in the same line.
	PlaceholderVerticalAlignTextTop

	// PlaceholderVerticalAlignTextBottom aligns the bottom of the placeholder with the bottom of the proceeding text.
	// Different from Bottom when there are texts with different font sizes in the same line.
	PlaceholderVerticalAlignTextBottom

	// PlaceholderVerticalAlignTextCenter aligns the center of the placeholder with the center of the proceeding text.
	// Different from Center when there are texts with different font sizes in the same line.
	PlaceholderVerticalAlignTextCenter
)

func (PlaceholderVerticalAlign) String

func (p PlaceholderVerticalAlign) String() string

String returns the string representation of the PlaceholderVerticalAlign.

type PlatformParagraphStyle

type PlatformParagraphStyle struct {
}

PlatformParagraphStyle contains platform-specific paragraph styling.

var PlatformParagraphStyleUnspecified *PlatformParagraphStyle = &PlatformParagraphStyle{}

func TakeOrElsePlatformParagraphStyle

func TakeOrElsePlatformParagraphStyle(s, def *PlatformParagraphStyle) *PlatformParagraphStyle

type PlatformSpanStyle

type PlatformSpanStyle struct {
}

PlatformSpanStyle contains platform-specific text styling.

var PlatformSpanStyleUnspecified *PlatformSpanStyle = &PlatformSpanStyle{}

func LerpPlatformSpanStyle

func LerpPlatformSpanStyle(start, stop *PlatformSpanStyle, fraction float32) *PlatformSpanStyle

func TakeOrElsePlatformSpanStyle

func TakeOrElsePlatformSpanStyle(s, def *PlatformSpanStyle) *PlatformSpanStyle

type PlatformTextStyle

type PlatformTextStyle struct {
	SpanStyle      *PlatformSpanStyle
	ParagraphStyle *PlatformParagraphStyle
}

PlatformTextStyle contains platform-specific text styling combining span and paragraph styles.

var PlatformTextStyleUnspecified *PlatformTextStyle = &PlatformTextStyle{
	SpanStyle:      PlatformSpanStyleUnspecified,
	ParagraphStyle: PlatformParagraphStyleUnspecified,
}

func TakeOrElsePlatformTextStyle

func TakeOrElsePlatformTextStyle(s, def *PlatformTextStyle) *PlatformTextStyle

type Range

type Range[T any] struct {
	Item  T
	Start int
	End   int
	Tag   string
}

Range represents an annotation applied to a half-open range [Start, End).

func NewRange

func NewRange[T any](item T, start, end int) Range[T]

NewRange creates a Range with the given item and bounds.

func NewRangeWithTag

func NewRangeWithTag[T any](item T, start, end int, tag string) Range[T]

NewRangeWithTag creates a Range with an additional tag for identification.

type SpanStyle

type SpanStyle struct {
	FontSize               unit.TextUnit
	FontWeight             font.FontWeight
	FontStyle              font.FontStyle
	FontSynthesis          *font.FontSynthesis
	FontFamily             font.FontFamily
	FontFeatureSettings    string
	LetterSpacing          unit.TextUnit
	BaselineShift          style.BaselineShift
	TextGeometricTransform *style.TextGeometricTransform
	LocaleList             *intl.LocaleList
	Background             graphics.Color
	TextDecoration         *style.TextDecoration
	Shadow                 *graphics.Shadow
	PlatformStyle          *PlatformSpanStyle
	DrawStyle              graphics.DrawStyle
	// contains filtered or unexported fields
}
var SpanStyleUnspecified *SpanStyle = &SpanStyle{
	textForegroundStyle:    nil,
	FontSize:               unit.TextUnitUnspecified,
	FontWeight:             font.FontWeightUnspecified,
	FontStyle:              font.FontStyleUnspecified,
	FontSynthesis:          nil,
	FontFamily:             nil,
	FontFeatureSettings:    "",
	LetterSpacing:          unit.TextUnitUnspecified,
	BaselineShift:          style.BaselineShiftUnspecified,
	TextGeometricTransform: nil,
	LocaleList:             nil,
	Background:             graphics.ColorUnspecified,
	TextDecoration:         nil,
	Shadow:                 nil,
	PlatformStyle:          nil,
	DrawStyle:              nil,
}

func CoalesceSpanStyle

func CoalesceSpanStyle(ptr, def *SpanStyle) *SpanStyle

func LerpSpanStyle

func LerpSpanStyle(width, start, stop *SpanStyle, fraction float32) *SpanStyle

func MergeSpanStyle

func MergeSpanStyle(a, b *SpanStyle) *SpanStyle

func ResolveSpanStyleDefaults

func ResolveSpanStyleDefaults(s *SpanStyle) *SpanStyle

func SpanStyleResolveDefaults

func SpanStyleResolveDefaults(ss *SpanStyle) *SpanStyle

func TakeOrElseSpanStyle

func TakeOrElseSpanStyle(s, def *SpanStyle) *SpanStyle

func (SpanStyle) Alpha

func (s SpanStyle) Alpha() float32

func (SpanStyle) Brush

func (s SpanStyle) Brush() graphics.Brush

func (SpanStyle) Color

func (s SpanStyle) Color() graphics.Color

Props

func (SpanStyle) Copy

func (s SpanStyle) Copy(options ...SpanStyleOption) *SpanStyle

type SpanStyleOption

type SpanStyleOption = func(*SpanStyleOptions)

func SpanStyleWithBackground

func SpanStyleWithBackground(background graphics.Color) SpanStyleOption

func SpanStyleWithBaselineShift

func SpanStyleWithBaselineShift(baselineShift style.BaselineShift) SpanStyleOption

func SpanStyleWithBrush

func SpanStyleWithBrush(brush graphics.Brush, alpha float32) SpanStyleOption

func SpanStyleWithColor

func SpanStyleWithColor(color graphics.Color) SpanStyleOption

func SpanStyleWithDrawStyle

func SpanStyleWithDrawStyle(drawStyle graphics.DrawStyle) SpanStyleOption

func SpanStyleWithFontFamily

func SpanStyleWithFontFamily(fontFamily font.FontFamily) SpanStyleOption

func SpanStyleWithFontFeatureSettings

func SpanStyleWithFontFeatureSettings(fontFeatureSettings string) SpanStyleOption

func SpanStyleWithFontSize

func SpanStyleWithFontSize(fontSize unit.TextUnit) SpanStyleOption

func SpanStyleWithFontStyle

func SpanStyleWithFontStyle(fontStyle font.FontStyle) SpanStyleOption

func SpanStyleWithFontSynthesis

func SpanStyleWithFontSynthesis(fontSynthesis *font.FontSynthesis) SpanStyleOption

func SpanStyleWithFontWeight

func SpanStyleWithFontWeight(fontWeight font.FontWeight) SpanStyleOption

func SpanStyleWithLetterSpacing

func SpanStyleWithLetterSpacing(letterSpacing unit.TextUnit) SpanStyleOption

func SpanStyleWithLocaleList

func SpanStyleWithLocaleList(localeList *intl.LocaleList) SpanStyleOption

func SpanStyleWithPlatformStyle

func SpanStyleWithPlatformStyle(platformStyle *PlatformSpanStyle) SpanStyleOption

func SpanStyleWithShadow

func SpanStyleWithShadow(shadow *graphics.Shadow) SpanStyleOption

func SpanStyleWithTextDecoration

func SpanStyleWithTextDecoration(textDecoration *style.TextDecoration) SpanStyleOption

func SpanStyleWithTextGeometricTransform

func SpanStyleWithTextGeometricTransform(textGeometricTransform *style.TextGeometricTransform) SpanStyleOption

type SpanStyleOptions

type SpanStyleOptions struct {
	FontSize               unit.TextUnit
	FontWeight             font.FontWeight
	FontStyle              font.FontStyle
	FontSynthesis          *font.FontSynthesis
	FontFamily             font.FontFamily
	FontFeatureSettings    string
	LetterSpacing          unit.TextUnit
	BaselineShift          style.BaselineShift
	TextGeometricTransform *style.TextGeometricTransform
	LocaleList             *intl.LocaleList
	Background             graphics.Color
	TextDecoration         *style.TextDecoration
	Shadow                 *graphics.Shadow
	PlatformStyle          *PlatformSpanStyle
	DrawStyle              graphics.DrawStyle
	// contains filtered or unexported fields
}

type StringAnnotation

type StringAnnotation string

StringAnnotation is simple string metadata attached to text.

type TextLayoutInput

type TextLayoutInput struct {
	// Text is the annotated string used for computing text layout.
	Text AnnotatedString

	// Style is the text style used for computing this text layout.
	Style TextStyle

	// Placeholders is a list of placeholders inserted into text layout that reserve space
	// to embed icons or custom emojis.
	Placeholders []Range[Placeholder]

	// MaxLines is the maximum number of lines for the text layout.
	MaxLines int

	// SoftWrap indicates whether the text should break at soft line breaks.
	SoftWrap bool

	// Overflow indicates how visual overflow should be handled.
	Overflow style.TextOverFlow

	// Density is the density used for computing this text layout.
	Density unit.Density

	// LayoutDirection is the layout direction used for computing this text layout.
	LayoutDirection unit.LayoutDirection

	// FontFamilyResolver is the font resolver used for computing this text layout.
	// This is a placeholder interface for platform-specific implementations.
	FontFamilyResolver interface{}

	// Constraints are the layout constraints for this text layout.
	Constraints unit.Constraints
}

TextLayoutInput holds the parameters used for computing a text layout result.

Note: The Kotlin source includes deprecated resourceLoader field and DeprecatedBridgeFontResourceLoader class. These are omitted in the Go port.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/TextLayoutResult.kt

func NewTextLayoutInput

func NewTextLayoutInput(
	text AnnotatedString,
	textStyle TextStyle,
	placeholders []Range[Placeholder],
	maxLines int,
	softWrap bool,
	overflow style.TextOverFlow,
	density unit.Density,
	layoutDirection unit.LayoutDirection,
	fontFamilyResolver interface{},
	constraints unit.Constraints,
) TextLayoutInput

NewTextLayoutInput creates a new TextLayoutInput with the given parameters.

func (TextLayoutInput) Equals

func (i TextLayoutInput) Equals(other TextLayoutInput) bool

Equals checks equality with another TextLayoutInput.

func (TextLayoutInput) String

func (i TextLayoutInput) String() string

String returns a string representation of TextLayoutInput.

type TextLayoutResult

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

TextLayoutResult holds the result of text layout computation.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/TextLayoutResult.kt

func NewTextLayoutResult

func NewTextLayoutResult(layoutInput TextLayoutInput, multiParagraph MultiParagraph, size unit.IntSize) TextLayoutResult

NewTextLayoutResult creates a new TextLayoutResult.

func (TextLayoutResult) Copy

func (r TextLayoutResult) Copy(layoutInput *TextLayoutInput, size *unit.IntSize) TextLayoutResult

Copy creates a copy of the TextLayoutResult with optional overrides.

func (TextLayoutResult) DidOverflowHeight

func (r TextLayoutResult) DidOverflowHeight() bool

DidOverflowHeight returns true if the text is too tall and couldn't fit with given height.

func (TextLayoutResult) DidOverflowWidth

func (r TextLayoutResult) DidOverflowWidth() bool

DidOverflowWidth returns true if the text is too wide and couldn't fit with given width.

func (TextLayoutResult) Equals

func (r TextLayoutResult) Equals(other TextLayoutResult) bool

Equals checks equality with another TextLayoutResult.

func (TextLayoutResult) FirstBaseline

func (r TextLayoutResult) FirstBaseline() float32

FirstBaseline returns the distance from the top to the alphabetic baseline of the first line.

func (TextLayoutResult) GetBidiRunDirection

func (r TextLayoutResult) GetBidiRunDirection(offset int) style.ResolvedTextDirection

GetBidiRunDirection returns the text direction of the BiDi run at the offset.

func (TextLayoutResult) GetBoundingBox

func (r TextLayoutResult) GetBoundingBox(offset int) geometry.Rect

GetBoundingBox returns the bounding box of the character at the given offset.

func (TextLayoutResult) GetCursorRect

func (r TextLayoutResult) GetCursorRect(offset int) geometry.Rect

GetCursorRect returns the rectangle of the cursor area at the given offset.

func (TextLayoutResult) GetHorizontalPosition

func (r TextLayoutResult) GetHorizontalPosition(offset int, usePrimaryDirection bool) float32

GetHorizontalPosition returns the horizontal position for the specified text offset.

func (TextLayoutResult) GetLineBaseline

func (r TextLayoutResult) GetLineBaseline(lineIndex int) float32

GetLineBaseline returns the baseline y coordinate of the given line.

func (TextLayoutResult) GetLineBottom

func (r TextLayoutResult) GetLineBottom(lineIndex int) float32

GetLineBottom returns the bottom y coordinate of the given line.

func (TextLayoutResult) GetLineEnd

func (r TextLayoutResult) GetLineEnd(lineIndex int, visibleEnd bool) int

GetLineEnd returns the end offset of the given line.

func (TextLayoutResult) GetLineForOffset

func (r TextLayoutResult) GetLineForOffset(offset int) int

GetLineForOffset returns the line number for the specified text offset.

func (TextLayoutResult) GetLineForVerticalPosition

func (r TextLayoutResult) GetLineForVerticalPosition(vertical float32) int

GetLineForVerticalPosition returns the line number closest to the given vertical position.

func (TextLayoutResult) GetLineLeft

func (r TextLayoutResult) GetLineLeft(lineIndex int) float32

GetLineLeft returns the left x coordinate of the given line.

func (TextLayoutResult) GetLineRight

func (r TextLayoutResult) GetLineRight(lineIndex int) float32

GetLineRight returns the right x coordinate of the given line.

func (TextLayoutResult) GetLineStart

func (r TextLayoutResult) GetLineStart(lineIndex int) int

GetLineStart returns the start offset of the given line, inclusive.

func (TextLayoutResult) GetLineTop

func (r TextLayoutResult) GetLineTop(lineIndex int) float32

GetLineTop returns the top y coordinate of the given line.

func (TextLayoutResult) GetOffsetForPosition

func (r TextLayoutResult) GetOffsetForPosition(position geometry.Offset) int

GetOffsetForPosition returns the character offset closest to the given graphical position.

func (TextLayoutResult) GetParagraphDirection

func (r TextLayoutResult) GetParagraphDirection(offset int) style.ResolvedTextDirection

GetParagraphDirection returns the text direction of the paragraph containing the offset.

func (TextLayoutResult) GetPathForRange

func (r TextLayoutResult) GetPathForRange(start, end int) graphics.Path

GetPathForRange returns a path that encloses the given text range.

func (TextLayoutResult) GetWordBoundary

func (r TextLayoutResult) GetWordBoundary(offset int) TextRange

GetWordBoundary returns the text range of the word at the given offset.

func (TextLayoutResult) HasVisualOverflow

func (r TextLayoutResult) HasVisualOverflow() bool

HasVisualOverflow returns true if either vertical or horizontal overflow happens.

func (TextLayoutResult) IsLineEllipsized

func (r TextLayoutResult) IsLineEllipsized(lineIndex int) bool

IsLineEllipsized returns true if the given line is ellipsized.

func (TextLayoutResult) LastBaseline

func (r TextLayoutResult) LastBaseline() float32

LastBaseline returns the distance from the top to the alphabetic baseline of the last line.

func (TextLayoutResult) LayoutInput

func (r TextLayoutResult) LayoutInput() TextLayoutInput

LayoutInput returns the parameters used for computing this text layout result.

func (TextLayoutResult) LineCount

func (r TextLayoutResult) LineCount() int

LineCount returns the number of lines in this text layout.

func (TextLayoutResult) MultiParagraph

func (r TextLayoutResult) MultiParagraph() MultiParagraph

MultiParagraph returns the underlying multi-paragraph object.

func (TextLayoutResult) PlaceholderRects

func (r TextLayoutResult) PlaceholderRects() []*geometry.Rect

PlaceholderRects returns the bounding boxes for placeholders.

func (TextLayoutResult) Size

func (r TextLayoutResult) Size() unit.IntSize

Size returns the size of this text layout in pixels.

func (TextLayoutResult) String

func (r TextLayoutResult) String() string

String returns a string representation of TextLayoutResult.

type TextRange

type TextRange struct {
	Start int
	End   int
}

TextRange is an immutable text range, representing a range from Start (inclusive) to End (exclusive). End can be smaller than Start; use Min() and Max() to get ordered values.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/next/text/TextRange.kt

func NewTextRange

func NewTextRange(start, end int) TextRange

NewTextRange creates a new TextRange with the given start and end. Panics if start or end is negative.

func NewTextRangeCollapsed

func NewTextRangeCollapsed(index int) TextRange

NewTextRangeCollapsed creates a TextRange where start equals end.

func (TextRange) CoerceIn

func (r TextRange) CoerceIn(minimumValue, maximumValue int) TextRange

CoerceIn ensures that Start and End values lie in the specified range. For each value: - if value is smaller than minimumValue, value is replaced by minimumValue - if value is greater than maximumValue, value is replaced by maximumValue

func (TextRange) Collapsed

func (r TextRange) Collapsed() bool

Collapsed returns true if the range is collapsed (start == end).

func (TextRange) Contains

func (r TextRange) Contains(other TextRange) bool

Contains returns true if this range covers including equals with the given range.

func (TextRange) ContainsOffset

func (r TextRange) ContainsOffset(offset int) bool

ContainsOffset returns true if the given offset is a part of this range.

func (TextRange) Equals

func (r TextRange) Equals(other TextRange) bool

Equals checks equality with another TextRange.

func (TextRange) Intersects

func (r TextRange) Intersects(other TextRange) bool

Intersects returns true if the given range has intersection with this range.

func (TextRange) Length

func (r TextRange) Length() int

Length returns the length of the range.

func (TextRange) Max

func (r TextRange) Max() int

Max returns the maximum offset of the range.

func (TextRange) Min

func (r TextRange) Min() int

Min returns the minimum offset of the range.

func (TextRange) Reversed

func (r TextRange) Reversed() bool

Reversed returns true if the start offset is larger than the end offset.

func (TextRange) String

func (r TextRange) String() string

String returns a string representation of the TextRange.

func (TextRange) Substring

func (r TextRange) Substring(s string) string

Substring returns the substring of s corresponding to this TextRange.

type TextShaper

type TextShaper struct {
	Shaper *text.Shaper
}

type TextStyle

type TextStyle struct {
	// contains filtered or unexported fields
}
var TextStyleUnspecified *TextStyle = &TextStyle{
	spanStyle:      SpanStyleUnspecified,
	paragraphStyle: ParagraphStyleUnspecified,
	platformStyle:  nil,
}

func CoalesceTextStyle

func CoalesceTextStyle(ptr, def *TextStyle) *TextStyle

func MergeTextStyle

func MergeTextStyle(a, b *TextStyle) *TextStyle

func TakeOrElseTextStyle

func TakeOrElseTextStyle(style, defaultStyle *TextStyle) *TextStyle

func TextStyleResolveDefaults

func TextStyleResolveDefaults(ts *TextStyle, direction unit.LayoutDirection) *TextStyle

func (TextStyle) Alpha

func (ts TextStyle) Alpha() float32

func (TextStyle) Background

func (ts TextStyle) Background() graphics.Color

func (TextStyle) BaselineShift

func (ts TextStyle) BaselineShift() style.BaselineShift

func (TextStyle) Brush

func (ts TextStyle) Brush() graphics.Brush

func (TextStyle) Color

func (ts TextStyle) Color() graphics.Color

func (TextStyle) Copy

func (ts TextStyle) Copy() *TextStyle

func (TextStyle) DrawStyle

func (ts TextStyle) DrawStyle() graphics.DrawStyle

func (TextStyle) FontFamily

func (ts TextStyle) FontFamily() font.FontFamily

func (TextStyle) FontFeatureSettings

func (ts TextStyle) FontFeatureSettings() string

func (TextStyle) FontSize

func (ts TextStyle) FontSize() unit.TextUnit

func (TextStyle) FontStyle

func (ts TextStyle) FontStyle() font.FontStyle

func (TextStyle) FontSynthesis

func (ts TextStyle) FontSynthesis() *font.FontSynthesis

func (TextStyle) FontWeight

func (ts TextStyle) FontWeight() font.FontWeight

func (TextStyle) Hyphens

func (ts TextStyle) Hyphens() style.Hyphens

func (TextStyle) LetterSpacing

func (ts TextStyle) LetterSpacing() unit.TextUnit

func (TextStyle) LineBreak

func (ts TextStyle) LineBreak() style.LineBreak

func (TextStyle) LineHeight

func (ts TextStyle) LineHeight() unit.TextUnit

func (TextStyle) LineHeightStyle

func (ts TextStyle) LineHeightStyle() *style.LineHeightStyle

func (TextStyle) LocaleList

func (ts TextStyle) LocaleList() *intl.LocaleList

func (TextStyle) MergeParagraphStyle

func (ts TextStyle) MergeParagraphStyle(other *ParagraphStyle) *TextStyle

func (TextStyle) MergeSpanStyle

func (ts TextStyle) MergeSpanStyle(other *SpanStyle) *TextStyle

func (*TextStyle) Plus

func (ts *TextStyle) Plus(other *TextStyle) *TextStyle

func (TextStyle) PlusParagraphStyle

func (ts TextStyle) PlusParagraphStyle(other *ParagraphStyle) *TextStyle

func (TextStyle) PlusSpanStyle

func (ts TextStyle) PlusSpanStyle(other *SpanStyle) *TextStyle

func (TextStyle) Shadow

func (ts TextStyle) Shadow() *graphics.Shadow

func (TextStyle) TextAlign

func (ts TextStyle) TextAlign() style.TextAlign

func (TextStyle) TextDecoration

func (ts TextStyle) TextDecoration() *style.TextDecoration

func (TextStyle) TextDirection

func (ts TextStyle) TextDirection() style.TextDirection

func (TextStyle) TextGeometricTransform

func (ts TextStyle) TextGeometricTransform() *style.TextGeometricTransform

func (TextStyle) TextIndent

func (ts TextStyle) TextIndent() *style.TextIndent

func (TextStyle) TextMotion

func (ts TextStyle) TextMotion() *style.TextMotion

func (TextStyle) ToParagraphStyle

func (ts TextStyle) ToParagraphStyle() *ParagraphStyle

func (TextStyle) ToPlatformTextStyle

func (ts TextStyle) ToPlatformTextStyle() *PlatformTextStyle

func (TextStyle) ToSpanStyle

func (ts TextStyle) ToSpanStyle() *SpanStyle

func (TextStyle) ToString

func (s TextStyle) ToString() string

type TextStyleInterface

type TextStyleInterface interface {
	Alpha() float32
	Background() graphics.Color
	BaselineShift() style.BaselineShift
	Brush() graphics.Brush
	Color() graphics.Color
	Copy() *TextStyle
	DrawStyle() graphics.DrawStyle
	FontFamily() font.FontFamily
	FontFeatureSettings() string
	FontSize() unit.TextUnit
	FontStyle() font.FontStyle
	FontSynthesis() *font.FontSynthesis
	FontWeight() font.FontWeight
	Hyphens() style.Hyphens
	LetterSpacing() unit.TextUnit
	LineBreak() style.LineBreak
	LineHeight() unit.TextUnit
	LineHeightStyle() *style.LineHeightStyle
	LocaleList() *intl.LocaleList
	MergeParagraphStyle(other *ParagraphStyle) *TextStyle
	MergeSpanStyle(other *SpanStyle) *TextStyle
	Plus(other *TextStyle) *TextStyle
	PlusParagraphStyle(other *ParagraphStyle) *TextStyle
	PlusSpanStyle(other *SpanStyle) *TextStyle
	Shadow() *graphics.Shadow
	TextAlign() style.TextAlign
	TextDecoration() *style.TextDecoration
	TextDirection() style.TextDirection
	TextGeometricTransform() *style.TextGeometricTransform
	TextIndent() *style.TextIndent
	TextMotion() *style.TextMotion
	ToParagraphStyle() *ParagraphStyle
	ToPlatformTextStyle() *PlatformTextStyle
	ToSpanStyle() *SpanStyle
	ToString() string
}

type TtsAnnotation

type TtsAnnotation struct {
}

TtsAnnotation provides text-to-speech metadata.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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