richtext

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: 11 Imported by: 0

Documentation

Overview

Package richtext provides rendering of text containing multiple fonts, styles, and levels of interactivity.

Index

Constants

This section is empty.

Variables

View Source
var LongPressDuration time.Duration = 250 * time.Millisecond

LongPressDuration is the default duration of a long press gesture. Override this variable to change the detection threshold.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type EventType
	// ClickData is only populated if Type == Clicked
	ClickData gesture.ClickEvent
}

Event describes an interaction with rich text.

type EventType

type EventType uint8

EventType describes a kind of interaction with rich text.

const (
	Hover EventType = iota
	LongPress
	Click
)

type InteractiveSpan

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

InteractiveSpan holds the persistent state of rich text that can be interacted with by the user. It can report clicks, hovers, and long-presses on the text.

func (*InteractiveSpan) Content

func (i *InteractiveSpan) Content() (string, map[string]interface{})

Content returns the text content of the interactive span as well as the metadata associated with it.

func (*InteractiveSpan) Events

func (i *InteractiveSpan) Events() []Event

Events returns click event information for this span.

func (*InteractiveSpan) Get

func (i *InteractiveSpan) Get(key string) interface{}

Get looks up a metadata property on the interactive span.

func (*InteractiveSpan) Layout

Layout adds the pointer input op for this interactive span and updates its state. It uses the most recent pointer.AreaOp as its input area.

type InteractiveText

type InteractiveText struct {
	Spans []InteractiveSpan
}

InteractiveText holds persistent state for a block of text containing spans that may be interactive.

func (*InteractiveText) Events

func (i *InteractiveText) Events() (*InteractiveSpan, []Event)

Events returns the first span with unprocessed events and the events that need processing for it.

type SpanStyle

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

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

SpanStyle describes the appearance of a span of styled text.

func (*SpanStyle) DeepCopy

func (ss *SpanStyle) DeepCopy() SpanStyle

DeepCopy returns an identical SpanStyle with its own copy of its metadata.

func (*SpanStyle) Set

func (ss *SpanStyle) Set(key string, value interface{})

Set configures a metadata key-value pair on the span that can be retrieved if the span is interacted with. If the provided value is empty, the key will be deleted from the metadata.

type TextStyle

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

TextStyle presents rich text.

func Text

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

Text constructs a TextStyle.

func (TextStyle) Layout

func (t TextStyle) Layout(gtx layout.Context) layout.Dimensions

Layout renders the TextStyle.

Jump to

Keyboard shortcuts

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