text

package
v0.0.0-...-6aa7f09 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package text implements texture rendering from font texture map

Index

Constants

View Source
const (
	// OverflowOverlap let the text overflow the boundary
	OverflowOverlap = Overflow(iota)
	// OverflowWordWrap breaks lines on spaces and char by char if no space
	OverflowWordWrap
	// OverflowBreakWord breaks words
	OverflowBreakWord
)
View Source
const (
	AlignStart = Align(iota)
	AlignCenter
	AlignEnd
)

Text Alignment types.

View Source
const (
	ModeFlow = Mode(iota)
	ModeRaw
)

Flow modes

Variables

This section is empty.

Functions

This section is empty.

Types

type Align

type Align int

Align type for specifying text alignment.

func (Align) String

func (a Align) String() string

type Entity

type Entity struct {
	gorge.TransformComponent
	gorge.RenderableComponent
	gorge.ColorableComponent
	// contains filtered or unexported fields
}

Entity renderable entity

func New

func New(font *Font, opts ...MeshFunc) *Entity

New setups the renderable with a font

func (*Entity) SetTextf

func (t *Entity) SetTextf(f string, args ...any)

SetTextf sets formated text

type Font

type Font struct {
	Face     font.Face
	Glyphs   map[rune]Glyph
	SpaceAdv float32
	// Size is the internally rendered size
	Size float32
	*gorge.Texture
}

Font is like a texture with extra information about glyphs

func (*Font) Glyph

func (f *Font) Glyph(ch rune) Glyph

type FontOptions

type FontOptions struct {
	Resolution int
	Chars      []rune
	Background *gm.Vec4
	Foreground *gm.Vec4
}

FontOptions options for font

type FontOptionsFunc

type FontOptionsFunc func(o *FontOptions)

FontOptionsFunc func to manipulate font options.

func FontBackground

func FontBackground(c gm.Vec4) FontOptionsFunc

FontBackground sets the font texture background option.

func FontForeground

func FontForeground(c gm.Vec4) FontOptionsFunc

FontForeground sets the font texture foreground option.

func FontResolution

func FontResolution(n int) FontOptionsFunc

FontResolution sets the font texture resolution option.

func FontRunes

func FontRunes(chars []rune) FontOptionsFunc

FontRunes sets the font texture runes option.

type Glyph

type Glyph struct {
	Uv1  gm.Vec2
	Uv2  gm.Vec2
	Size gm.Vec2

	Advance  float32
	BearingH float32
	BearingV float32
}

Glyph char information

type Mesh

type Mesh struct {
	Text string
	// Boundary counting from starting Point
	Boundary gm.Vec2
	// Wrap just naive string wrap, should have better options
	Alignment Align
	Overflow  Overflow
	// Size 0 will return a default size (1)
	Size float32
	Mode Mode

	Font *Font

	// TODO: {lpf} Calculated values should be private and functions added
	Min, Max gm.Vec2
	Lines    int
	// contains filtered or unexported fields
}

Mesh to be used on renderable update must be called to update the mesh after changing.

func NewMesh

func NewMesh(font *Font, opts ...MeshFunc) *Mesh

NewMesh returns a new Text Mesh.

func (*Mesh) MeasureWidth

func (m *Mesh) MeasureWidth(w []rune) float32

MeasureWidth measures a width of a text best usage without "\n"

func (*Mesh) SetAlignment

func (m *Mesh) SetAlignment(a Align)

SetAlignment sets the horizontal alignment based on boundary and updates underlying mesh.

func (*Mesh) SetBoundary

func (m *Mesh) SetBoundary(w, h float32)

SetBoundary set text boundary, and updates mesh.

func (*Mesh) SetFont

func (m *Mesh) SetFont(font *Font)

SetFont sets the font used to draw the vertices, Material texture should change too to show the assigned font.

func (*Mesh) SetMode

func (m *Mesh) SetMode(mm Mode)

SetMode sets text flow mode and updates underlying mesh.

func (*Mesh) SetOverflow

func (m *Mesh) SetOverflow(o Overflow)

SetOverflow sets text overflow based on boundary and updates underlying mesh.

func (*Mesh) SetSize

func (m *Mesh) SetSize(v float32)

SetSize sets the relative font size.

func (*Mesh) SetText

func (m *Mesh) SetText(a ...any)

SetText sets the text and updates underlying mesh.

func (*Mesh) Update

func (m *Mesh) Update()

Update Mesh Ideas:

  • grab a line, for { measure, remove last word } until we get a proper size

type MeshFunc

type MeshFunc func(t *Mesh)

MeshFunc allows mesh function options to be added in initializator

func Boundary

func Boundary(w, h float32) MeshFunc

Boundary returns a func that applies a boundary to mesh.

type Mode

type Mode int

Mode is a type to indicate text flow mode.

func (Mode) String

func (m Mode) String() string

type Overflow

type Overflow int

Overflow type for specifying text overflow.

func (Overflow) String

func (o Overflow) String() string

Jump to

Keyboard shortcuts

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