Skip to Content
Onevra

RichText

A paragraph of styled spans with inline text and link buttons.

Loading the live example…

rich_text.go
import (
	"fmt"

	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type release struct {
	reads int
}

func (r *release) View(c *ui.Context) {
	t := c.Theme()
	components.RichText(c,
		ui.Span{Text: "Onevra 2.4 ", Weight: 600},
		ui.Span{Text: "adds "},
		ui.Span{Text: "TagInput", Background: t.SurfaceHover, Radius: 4},
		ui.Span{Text: ", faster tables and "},
		ui.Span{Text: "fewer surprises", Italic: true, Underline: true},
		ui.Span{Text: ". "},
	).Children(func() {
		if components.Button(c, "Read the notes", components.ButtonLink).Clicked() {
			r.reads++
		}
		if r.reads > 0 {
			components.Text(c, fmt.Sprintf(" (opened %d times)", r.reads)).TextColor(t.TextMuted)
		}
	}).MaxWidth(360)
}
Source

components.RichText composes ui.Span values and inline children, such as components.Text and link buttons, into one wrapping paragraph. Zero fields of a span inherit the surrounding style.

API

RichText

func RichText(c *ui.Context, spans ...ui.Span) ui.Element

RichText composes styled spans and inline Text or ButtonLink children into a single wrapping paragraph. Zero span fields inherit the surrounding style. MyGo's unstyled text primitive owns shaping, selection, inline interaction and accessibility; only text elements belong in Children.

pkg.go.dev
Edit this page on GitHub

On this page