styledtext

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT, Unlicense Imports: 12 Imported by: 2

README

styledtext

Provides a widget that renders text in different styles.

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    font.Font
	Size    unit.Sp
	Color   color.NRGBA
	Content string
	// 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
	WrapPolicy WrapPolicy
	*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.

type WrapPolicy added in v0.3.0

type WrapPolicy uint8

WrapPolicy defines line wrapping policies for styledtext. Due to complexities of the styledtext implementation, there are fewer options available than in gioui.org/text.WrapPolicy.

const (
	// WrapWords implements behavior like [gioui.org/text/.WrapWords]. This is the default,
	// as it prevents words from being split across lines.
	WrapWords WrapPolicy = iota
	// WrapWords implements behavior like [gioui.org/text/.WrapGraphemes]. This often gives
	// unpleasant results, as it will choose to split words across lines whenever it can. Some
	// use-cases may still want this, however.
	WrapGraphemes
)

Jump to

Keyboard shortcuts

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