Skip to Content
Onevra

Text

Text in the theme's style, wrapping, truncated or editable in place.

Loading the live example…

text.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type textStyles struct {
	title string
}

func (s *textStyles) View(c *ui.Context) {
	t := c.Theme()
	ui.Column(c).Width(380).MaxWidthPercent(100).Gap(10).Children(func() {
		// Editable text edits in place, without a field around it.
		components.Text(c, s.title, components.TextOptions{Editable: &s.title}).
			Label("Project name").FontSize(t.Rem(1.4)).Bold()
		components.Text(c, "Click the title above to rename the project.").TextColor(t.TextMuted)
		components.Text(c, "Long text wraps within the available width, including in narrow windows.").
			FillWidth()
		components.Text(c, "A single line truncates when it does not fit, rather than wrapping.").
			SingleLine().Ellipsis("…").FillWidth()
	})
}
Source

components.Text inherits the theme's font, size and color. With TextOptions.Editable, it edits a *string in place, like an inline name, without a field around it; Changed() and Submitted() report edits and Enter.

API

Text

func Text(c *ui.Context, value string, options ...TextOptions) *TextControl

Text creates text inheriting the frame theme and parent font, size and color. With no Editable binding it is MyGo's text primitive, including wrapping and RichText composition. Editable text is single-line, like an inline name, and adds only the native editor's caret and selection, not a background, border, padding or focus ring. MyGo owns input, shaping and rendering.

text := Text(c, name, TextOptions{Editable: &name})
text.Label("Name").Bold()
if text.Changed() { /* use name */ }

Apply layout and typography to the returned Element as usual. When editing, call Label and AutoFocus on TextControl before Element styling methods. Key a parent container for stable identity across reordering, not this element.

pkg.go.dev

TextOptions

TextOptions selects editing behavior without adding input decoration.

Prop

Type

pkg.go.dev

TextControl

TextControl exposes the layout element. Keep this handle to query Changed or Submitted after applying Element methods, which return ui.Element.

Prop

Type

Methods
func (t *TextControl) AutoFocus() *TextControl

AutoFocus focuses the editor when editing is enabled.

func (t *TextControl) Changed() bool

Changed reports a user edit to the bound value.

func (t *TextControl) Label(label string) *TextControl

Label supplies the accessible name of the text or its editor.

func (t *TextControl) Submitted() bool

Submitted reports Enter in editable text.

pkg.go.dev
Edit this page on GitHub

On this page