layout

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CombinedPos

type CombinedPos struct {
	// runes is the offset in runes.
	Runes   int
	LineCol ScreenPos
	// Pixel coordinates
	X               fixed.Int26_6
	Y               int
	Ascent, Descent fixed.Int26_6

	// RunIndex tracks which run this position is within, counted each time
	// we processes an end of run marker.
	RunIndex int
	// towardOrigin tracks whether this glyph's run is progressing toward the
	// origin or away from it.
	TowardOrigin bool
}

CombinedPos is a point in the editor.

func (CombinedPos) String

func (c CombinedPos) String() string

type Line

type Line struct {
	XOff    fixed.Int26_6
	YOff    int
	Width   fixed.Int26_6
	Ascent  fixed.Int26_6
	Descent fixed.Int26_6
	Glyphs  []*text.Glyph
	// runes is the number of runes represented by this line.
	Runes int
	// runeOff tracks the rune offset of the first rune of the line in the document.
	RuneOff int
}

Line contains various metrics of a line of text.

func (*Line) All added in v0.3.0

func (li *Line) All() iter.Seq[text.Glyph]

func (*Line) GetGlyphs

func (li *Line) GetGlyphs(offset, count int) []text.Glyph

func (Line) String

func (li Line) String() string

type Paragraph

type Paragraph struct {
	StartX fixed.Int26_6
	StartY int
	EndX   fixed.Int26_6
	EndY   int
	// Runes is the number of runes represented by this paragraph.
	Runes int
	// RuneOff tracks the rune offset of the first rune of the paragraph in the document.
	RuneOff int
}

Paragraph contains the pixel coordinates of the start and end position of the paragraph.

func (*Paragraph) Add

func (p *Paragraph) Add(li Line) bool

Add add a visual line to the paragraph, returning a boolean value indicating the end of a paragraph.

type Region

type Region struct {
	// Bounds is the coordinates of the bounding box relative to the containing
	// widget.
	Bounds image.Rectangle
	// Baseline is the quantity of vertical pixels between the baseline and
	// the bottom of bounds.
	Baseline int
}

Region describes the position and baseline of an area of interest within shaped text.

type ScreenPos

type ScreenPos struct {
	// col is the column, measured in runes.
	Col  int
	Line int
}

ScreenPos represents a character position in text line and column numbers, not pixels.

type TextLayout

type TextLayout struct {

	// Positions contain all possible caret positions, sorted by rune index.
	Positions []CombinedPos
	// lines contain metadata about the size and position of each line of
	// text on the screen.
	Lines []Line
	// Paragraphs contain size and position of each paragraph of text on the screen.
	Paragraphs []Paragraph
	// Graphemes tracks the indices of grapheme cluster boundaries within text source.
	Graphemes []int
	// contains filtered or unexported fields
}

func NewTextLayout

func NewTextLayout(src buffer.TextSource) TextLayout

func (*TextLayout) ClosestToLineCol

func (tl *TextLayout) ClosestToLineCol(lineCol ScreenPos) CombinedPos

func (*TextLayout) ClosestToRune

func (tl *TextLayout) ClosestToRune(runeIdx int) (CombinedPos, int)

func (*TextLayout) ClosestToXY

func (tl *TextLayout) ClosestToXY(x fixed.Int26_6, y int) CombinedPos

func (*TextLayout) Layout

func (tl *TextLayout) Layout(shaper *text.Shaper, params *text.Parameters, tabWidth int, wrapLine bool) layout.Dimensions

func (*TextLayout) Locate

func (tl *TextLayout) Locate(viewport image.Rectangle, startRune, endRune int, rects []Region) []Region

locate returns highlight regions covering the glyphs that represent the runes in [startRune,endRune). If the rects parameter is non-nil, locate will use it to return results instead of allocating, provided that there is enough capacity. The returned regions have their Bounds specified relative to the provided viewport.

Jump to

Keyboard shortcuts

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