styledtext

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package styledtext provides rendering of text containing multiple fonts and styles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SpanStyle

type SpanStyle struct {
	Font    text.Font
	Size    unit.Sp
	Color   color.NRGBA
	Content string

	Img image.Image
	// contains filtered or unexported fields
}

SpanStyle describes the appearance of a span of styled text.

func (SpanStyle) Layout

func (ss SpanStyle) Layout(gtx layout.Context, shape spanShape) layout.Dimensions

Layout renders the span using the provided text shaping.

type TextStyle

type TextStyle struct {
	Styles    []SpanStyle
	Alignment text.Alignment
	*text.Shaper
}

TextStyle presents rich text.

func Text

func Text(shaper *text.Shaper, styles ...SpanStyle) TextStyle

Text constructs a TextStyle.

func (TextStyle) Layout

func (t TextStyle) Layout(gtx layout.Context, spanFn func(gtx layout.Context, idx int, dims layout.Dimensions)) layout.Dimensions

Layout renders the TextStyle.

The spanFn function, if not nil, gets called for each span after it has been drawn, with the offset set to the span's top left corner. This can be used to set up input handling, for example.

The context's maximum constraint is set to the span's dimensions, while the dims argument additionally provides the text's baseline. The idx argument is the span's index in TextStyle.Styles. The function may get called multiple times with the same index if a span has to be broken across multiple lines.

Jump to

Keyboard shortcuts

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