rowtext

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rowtext lays out the text of one row of cells across the columns on screen, as Sheets does: values formatted and aligned, text running on into blank neighbors, cut to column boundaries in a single pass. It reads the sheet and nothing else, so drawing the grid can be measured and tested on its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap added in v0.3.0

func Wrap(text string, w int) []string

Wrap breaks text into lines at most w columns wide, as Sheets wraps a cell: at spaces where it can, inside a word longer than a line, and at every line break the text holds. It returns at least one line.

Types

type Line added in v0.3.0

type Line struct{ K, N int }

Line is one line of a row: the K-th of its N, from 0 at the top.

type Scratch added in v0.3.0

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

Scratch keeps the slices a layout works in, so the lines of a frame reuse them rather than allocate their own. The spans a layout through it returns hold until its next layout.

func (*Scratch) LayoutLine added in v0.3.0

func (sc *Scratch) LayoutLine(s *sheet.Sheet, row, lo, ncols, minCol, maxCol int, ln Line) []Span

LayoutLine is the package's LayoutLine, laid out in sc's slices.

type Shape added in v0.3.0

type Shape struct {
	Rule  bool
	Lines int
}

Shape is how a row is laid out: whether a border line comes above it, and how many lines its cells take.

type Shapes added in v0.3.0

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

Shapes works out the shape of rows as the grid asks for them, and keeps them until the sheet changes.

func (*Shapes) Row added in v0.3.0

func (x *Shapes) Row(s *sheet.Sheet, row int) Shape

Row returns the shape of row on s: its height when one is set, or enough lines for the text its cells wrap, and a rule line when a border lies along its top. Rows of a sheet that nothing shapes are a line each.

type Span

type Span struct {
	Lead  int
	Text  string
	Trail int
	Style sheet.Style
	Owner int // column of the cell the text belongs to

	// Left for the caller to fill in from the owner's value.
	Link  string // the owner's link target, drawn as a hyperlink
	Error bool   // the owner shows an error: its text gets the error mark
	// Invalid is set when the owner fails its data validation: its text
	// gets the invalid mark.
	Invalid bool
}

Span is what one grid column shows in a row: blank columns, the text, blank columns. Only the text takes the owning cell's text style, so an underline doesn't run into the padding.

func Layout

func Layout(s *sheet.Sheet, row, lo, ncols, minCol, maxCol int) []Span

Layout lays out ncols columns of row from lo, each span exactly its column's width. Text may run in from columns between minCol and maxCol, so it stops at the frozen columns' divider. Values are formatted with their cell's number format and aligned as Sheets does: numbers right, text left, booleans and errors centered, unless the cell sets an alignment. Text runs on into blank neighbors: to the right when left-aligned, to the left when right-aligned, both ways when centered. It can come from cells outside the viewport, so the scan starts at the nearest filled cell on each side.

func LayoutLine added in v0.3.0

func LayoutLine(s *sheet.Sheet, row, lo, ncols, minCol, maxCol int, ln Line) []Span

LayoutLine is Layout for one line of a row N lines tall. Values sit on the row's last line, as Sheets aligns them to the bottom, or its first or middle one as the cell's vertical alignment says, and text that wraps (sheet.WrapOn) fills lines of its own column around there, cut at the bottom when the row is too short. Clipped text (sheet.WrapClip) stays in its column. Text doesn't run on across a border or into merged cells, whose contents the caller draws (see Merged).

func Merged added in v0.3.0

func Merged(s *sheet.Sheet, m sheet.Rect, lo, hi int, show bool) []Span

Merged lays out a merged cell m over its columns from lo to hi (those on screen): its top-left cell's value when show is set, on the line of the merge that shows it, centered unless that cell is aligned and cut to the merge's width; blank otherwise.

Jump to

Keyboard shortcuts

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