textlayout

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LayoutLine

type LayoutLine struct {
	Text  string
	Width int
	Start int
	End   int // Exclusive
}

LayoutLine represents a single computed line of text within a bounding box.

type LayoutResult

type LayoutResult struct {
	Height    int
	LineCount int
	Lines     []LayoutLine
}

func Layout

func Layout(prepared *PreparedText, maxWidth int, lineHeight int) *LayoutResult

Layout performs pure arithmetic line-breaking using the cached segment widths. This is incredibly fast (O(N) arithmetic) and skips the GUI engine entirely.

type PreparedText

type PreparedText struct {
	Segments []Segment
	Font     fltk_bridge.Font
	FontSize int
}

PreparedText represents a string that has been split and measured, allowing for extremely fast layout calculations without re-measuring. Inspired by pretext (https://github.com/chenglou/pretext).

func Prepare

func Prepare(text string, font fltk_bridge.Font, fontSize int) *PreparedText

Prepare normalizes and breaks text into measurable segments (words, spaces, breaks), then measures each segment using FLTK's native font engine. This is the "expensive" step that should be cached.

type Segment

type Segment struct {
	Text  string
	Width int
	Type  SegmentType
}

Segment holds cached measurement data for a piece of text.

type SegmentType

type SegmentType int

SegmentType identifies the type of a text segment.

const (
	WordSegment SegmentType = iota
	SpaceSegment
	BreakSegment
)

Jump to

Keyboard shortcuts

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