styledtext

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Unlicense Imports: 11 Imported by: 0

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

View Source
var (
	Horizontal   = _l.Horizontal
	Vertical     = _l.Vertical
	Start        = _l.Start
	End          = _l.End
	Middle       = _l.Middle
	Baseline     = _l.Baseline
	SpaceSides   = _l.SpaceSides
	SpaceStart   = _l.SpaceStart
	SpaceEvenly  = _l.SpaceEvenly
	SpaceAround  = _l.SpaceAround
	SpaceBetween = _l.SpaceBetween
	SpaceEnd     = _l.SpaceEnd
)
View Source
var (
	Exact = _l.Exact
	Pt    = _i.Pt
)

Functions

This section is empty.

Types

type Alignment

type Alignment = _l.Alignment

type Axis

type Axis = _l.Axis

type Constraints

type Constraints = _l.Constraints

type Dim

type Dim = _l.Dimensions

type Dp

type Dp = _u.Dp

type Gx

type Gx = _l.Context

type List

type List = _l.List

type Point

type Point = _i.Point

type Rectangle

type Rectangle = _i.Rectangle

type Sp

type Sp = _u.Sp

type Spacing

type Spacing = _l.Spacing

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(g Gx, shape spanShape) Dim

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(g Gx, spanFn func(g Gx, idx int, dims Dim)) Dim

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 Widget

type Widget = _l.Widget

type WrapPolicy

type WrapPolicy uint8

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

const (
	// WrapWords implements behavior like [widget.mleku.dev/text/.WrapWords]. This is the default,
	// as it prevents words from being split across lines.
	WrapWords WrapPolicy = iota
	// WrapGraphemes implements behavior like [widget.mleku.dev/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