text

package
v0.0.0-...-225857b Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package text is a wrapper around the text rendering API part of github.com/hajimehoshi/ebiten/v2/text/v2.

It provides several additional conveniences that match how GUI text editing interfaces tend to work, including:

  • Basic types for styling text.
  • A styled String type that may interleave multiple styles along with helpers to efficiently construct them.
  • A text Box that renders text strictly within a well-defined area with overflow hidden.
  • An automatically-sized text box, AutoBox which allows simply drawing text and anchoring its position to a relative point in the box.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoBox

func AutoBox(dst *ebiten.Image, txt String, pos geom.Point, anchor geom.Dimensions)

AutoBox draws a text box with an automatically adjusted size to fit all the text at position pos.

anchor is a relative anchor point for the box. (0, 0) means top-left and (1, 1) means bottom-right of the box.

func Box

func Box(dst *ebiten.Image, txt String, bounds geom.AABB, boxOpts *BoxOptions)

Box draws a text box containing the provided text within the provided bounds, with any layout options applied.

Types

type Alignment

type Alignment int

Alignment describes horizontal text alignment.

const (
	AutoAlign Alignment = iota
	Left
	Center
	Right
)

type BoxOptions

type BoxOptions struct {
	// Padding sets the distance between the edge of the box and the text inside.
	Padding geom.Dimensions

	// LineSpacing is multiplier proportional to the size of each line of text.
	LineSpacing float64

	// Align sets the alignment of the text.
	Align Alignment

	// VertAlign sets the vertical alignment of the text.
	VertAlign VertAlignment
}

type Piece

type Piece struct {
	Text  string
	Style Style
}

Piece represents a piece of text with a consistent style.

func (Piece) String

func (p Piece) String() String

String creates a new String containing only the piece.

type String

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

String is a string of styled text.

All of the styles must have font face with an identical Direction.

func Concat

func Concat(pieces ...Piece) String

Concat concatenates a series of Pieces to form a String.

func (String) Concat

func (s String) Concat(t String) String

Concat concatenates the two styled Strings and returns the result.

func (String) Measure

func (s String) Measure(lineSpacing float64) geom.Dimensions

Measure returns the dimensions of the String once rendered.

type StringBuilder

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

StringBuilder is a builder for efficiently constructing styled strings. The zero value is ready for use.

func (*StringBuilder) Append

func (s *StringBuilder) Append(piece Piece)

Append appends the provided piece.

func (*StringBuilder) Reset

func (s *StringBuilder) Reset()

Reset resets the StringBuilder to be empty.

func (*StringBuilder) String

func (s *StringBuilder) String() String

String returns the builder's accumulated String.

type Style

type Style struct {
	Face  *font.Face
	Color color.Color
}

Style describes the style of text.

func Basic

func Basic(fontName string, size float64, c color.Color) Style

Basic creates a simple style from the provided font name, a font size, and a color. If the font doesn't exist, this falls back to 2d/ebiten's default font.

func (Style) Apply

func (s Style) Apply(text string) Piece

Apply applies the style to some text to produce a Piece of styled text.

func (Style) Recolor

func (s Style) Recolor(c color.Color) Style

Recolor returns a new style that's the same as this one but with a different color.

func (Style) Resize

func (s Style) Resize(size float64) Style

Resize returns a new style that's the same as this one but with a different font size.

type VertAlignment

type VertAlignment int

VertAlignment describes vertical text alignment.

const (
	AutoVertAlign VertAlignment = iota
	Top
	Middle
	Bottom
)

Jump to

Keyboard shortcuts

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