text

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aligns

type Aligns int32 //enums:enum -transform kebab

Aligns has the different types of alignment and justification for the text.

const (
	// Start aligns to the start (top, left) of text region.
	Start Aligns = iota

	// End aligns to the end (bottom, right) of text region.
	End

	// Center aligns to the center of text region.
	Center

	// Justify spreads words to cover the entire text region.
	Justify
)
const AlignsN Aligns = 4

AlignsN is the highest valid value for type Aligns, plus one.

func AlignsValues

func AlignsValues() []Aligns

AlignsValues returns all possible values for the type Aligns.

func (Aligns) Desc

func (i Aligns) Desc() string

Desc returns the description of the Aligns value.

func (Aligns) Factor

func (al Aligns) Factor() float32

Factor returns the alignment factor (0, .5, 1).

func (Aligns) Int64

func (i Aligns) Int64() int64

Int64 returns the Aligns value as an int64.

func (Aligns) MarshalText

func (i Aligns) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Aligns) SetInt64

func (i *Aligns) SetInt64(in int64)

SetInt64 sets the Aligns value from an int64.

func (*Aligns) SetString

func (i *Aligns) SetString(s string) error

SetString sets the Aligns value from its string representation, and returns an error if the string is invalid.

func (Aligns) String

func (i Aligns) String() string

String returns the string representation of this Aligns value.

func (*Aligns) UnmarshalText

func (i *Aligns) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Aligns) Values

func (i Aligns) Values() []enums.Enum

Values returns all possible values for the type Aligns.

type EditorSettings

type EditorSettings struct {

	// size of a tab, in chars; also determines indent level for space indent
	TabSize int `default:"4"`

	// use spaces for indentation, otherwise tabs
	SpaceIndent bool

	// wrap lines at word boundaries; otherwise long lines scroll off the end
	WordWrap bool `default:"true"`

	// whether to show line numbers
	LineNumbers bool `default:"true"`

	// use the completion system to suggest options while typing
	Completion bool `default:"true"`

	// suggest corrections for unknown words while typing
	SpellCorrect bool `default:"true"`

	// automatically indent lines when enter, tab, }, etc pressed
	AutoIndent bool `default:"true"`

	// use emacs-style undo, where after a non-undo command, all the current undo actions are added to the undo stack, such that a subsequent undo is actually a redo
	EmacsUndo bool

	// colorize the background according to nesting depth
	DepthColor bool `default:"true"`
}

EditorSettings contains text editor settings.

func (*EditorSettings) Defaults

func (es *EditorSettings) Defaults()

type Font

type Font struct {
	// StyleRune is the rune-compressed version of the [rich.Style] parameters.
	StyleRune rune

	// Size is the Text.Style.FontSize.Dots value of the font size,
	// multiplied by font rich.Style.Size.
	Size float32

	// Family is a nonstandard family name: if standard, then empty,
	// and value is determined by [rich.DefaultSettings] and Style.Family.
	Family string
}

Font is a compact encoding of font properties, which can be used to reconstruct the corresponding rich.Style from text.Style.

func NewFont

func NewFont(fsty *rich.Style, tsty *Style) *Font

func (*Font) FamilyString

func (fn *Font) FamilyString(tsty *Style) string

func (*Font) Style

func (fn *Font) Style(tsty *Style) *rich.Style

Style returns the rich.Style version of this Font.

type Style

type Style struct {

	// Align specifies how to align text along the default direction (inherited).
	// This *only* applies to the text within its containing element,
	// and is relevant only for multi-line text.
	Align Aligns

	// AlignV specifies "vertical" (orthogonal to default direction)
	// alignment of text (inherited).
	// This *only* applies to the text within its containing element:
	// if that element does not have a specified size
	// that is different from the text size, then this has *no effect*.
	AlignV Aligns

	// FontSize is the default font size. The rich text styling specifies
	// sizes relative to this value, with the normal text size factor = 1.
	// In the [styles.Style.Text] context, this is copied from [styles.Font.Size].
	FontSize units.Value

	// LineHeight is a multiplier on the default font size for spacing between lines.
	// If there are larger font elements within a line, they will be accommodated, with
	// the same amount of total spacing added above that maximum size as if it was all
	// the same height. The default of 1.3 represents standard "single spaced" text.
	LineHeight float32 `default:"1.3"`

	// ParaSpacing is the line spacing between paragraphs (inherited).
	// This will be copied from [Style.Margin] if that is non-zero,
	// or can be set directly. Like [LineHeight], this is a multiplier on
	// the default font size.
	ParaSpacing float32 `default:"1.5"`

	// WhiteSpace (not inherited) specifies how white space is processed,
	// and how lines are wrapped.  If set to WhiteSpaceNormal (default) lines are wrapped.
	// See info about interactions with Grow.X setting for this and the NoWrap case.
	WhiteSpace WhiteSpaces

	// Direction specifies the default text direction, which can be overridden if the
	// unicode text is typically written in a different direction.
	Direction rich.Directions

	// Indent specifies how much to indent the first line in a paragraph (inherited).
	Indent units.Value

	// TabSize specifies the tab size, in number of characters (inherited).
	TabSize int

	// Color is the default font fill color, used for inking fonts unless otherwise
	// specified in the [rich.Style].
	Color color.Color

	// SelectColor is the color to use for the background region of selected text (inherited).
	SelectColor image.Image

	// HighlightColor is the color to use for the background region of highlighted text (inherited).
	HighlightColor image.Image

	// CustomFont specifies the Custom font name for rich.Style.Family = Custom.
	CustomFont rich.FontName
}

Style is used for text layout styling. Most of these are inherited

func NewStyle

func NewStyle() *Style

func (*Style) AlignFactors

func (ts *Style) AlignFactors() (ax, ay float32)

AlignFactors gets basic text alignment factors

func (*Style) Defaults

func (ts *Style) Defaults()

func (*Style) FillColor

func (ts *Style) FillColor(sty *rich.Style) color.Color

FillColor returns the effective text fill color (main color) using any special setting in the given rich.Style, falling back on the Color setting on this text style.

func (*Style) FontFamily

func (ts *Style) FontFamily(sty *rich.Style) string

FontFamily returns the string value of the font Family for given rich.Style, using text.Style CustomFont or rich.DefaultSettings values.

func (*Style) FontHeight

func (ts *Style) FontHeight(sty *rich.Style) float32

FontHeight returns the effective font height based on FontSize * rich.Style Size multiplier.

func (*Style) FromProperties

func (s *Style) FromProperties(parent *Style, properties map[string]any, ctxt colors.Context)

FromProperties sets style field values based on the given property list.

func (*Style) FromProperty

func (s *Style) FromProperty(parent *Style, key string, val any, cc colors.Context)

FromProperty sets style field values based on the given property key and value.

func (*Style) InheritFields

func (ts *Style) InheritFields(parent *Style)

InheritFields from parent

func (*Style) LineHeightDots

func (ts *Style) LineHeightDots(sty *rich.Style) float32

LineHeightDots returns the effective line height in dots (actual pixels) as FontHeight * LineHeight

func (*Style) SetUnitContext

func (ts *Style) SetUnitContext(uc *units.Context)

SetUnitContext sets the font-specific information in the given units.Context, based on the given styles. Just uses standardized fractions of the font size for the other less common units such as ex, ch.

func (*Style) ToDots

func (ts *Style) ToDots(uc *units.Context)

ToDots runs ToDots on unit values, to compile down to raw pixels

func (*Style) ToProperties

func (s *Style) ToProperties(sty *rich.Style, p map[string]any)

ToProperties sets map[string]any properties based on non-default style values. properties map must be non-nil.

type WhiteSpaces

type WhiteSpaces int32 //enums:enum -trim-prefix WhiteSpace

WhiteSpaces determine how white space is processed and line wrapping occurs, either only at whitespace or within words.

const (
	// WrapAsNeeded means that all white space is collapsed to a single
	// space, and text wraps at white space except if there is a long word
	// that cannot fit on the next line, or would otherwise be truncated.
	// To get full word wrapping to expand to all available space, you also
	// need to set GrowWrap = true. Use the SetTextWrap convenience method
	// to set both.
	WrapAsNeeded WhiteSpaces = iota

	// WrapAlways is like [WrapAsNeeded] except that line wrap will always
	// occur within words if it allows more content to fit on a line.
	WrapAlways

	// WrapSpaceOnly means that line wrapping only occurs at white space,
	// and never within words. This means that long words may then exceed
	// the available space and will be truncated. White space is collapsed
	// to a single space.
	WrapSpaceOnly

	// WrapNever means that lines are never wrapped to fit. If there is an
	// explicit line or paragraph break, that will still result in
	// a new line. In general you also don't want simple non-wrapping
	// text labels to Grow (GrowWrap = false). Use the SetTextWrap method
	// to set both. White space is collapsed to a single space.
	WrapNever

	// WhiteSpacePre means that whitespace is preserved, including line
	// breaks. Text will only wrap on explicit line or paragraph breaks.
	// This acts like the <pre> tag in HTML.
	WhiteSpacePre

	// WhiteSpacePreWrap means that whitespace is preserved.
	// Text will wrap when necessary, and on line breaks
	WhiteSpacePreWrap
)
const WhiteSpacesN WhiteSpaces = 6

WhiteSpacesN is the highest valid value for type WhiteSpaces, plus one.

func WhiteSpacesValues

func WhiteSpacesValues() []WhiteSpaces

WhiteSpacesValues returns all possible values for the type WhiteSpaces.

func (WhiteSpaces) Desc

func (i WhiteSpaces) Desc() string

Desc returns the description of the WhiteSpaces value.

func (WhiteSpaces) HasWordWrap

func (ws WhiteSpaces) HasWordWrap() bool

HasWordWrap returns true if value supports word wrap.

func (WhiteSpaces) Int64

func (i WhiteSpaces) Int64() int64

Int64 returns the WhiteSpaces value as an int64.

func (WhiteSpaces) KeepWhiteSpace

func (ws WhiteSpaces) KeepWhiteSpace() bool

KeepWhiteSpace returns true if value preserves existing whitespace.

func (WhiteSpaces) MarshalText

func (i WhiteSpaces) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*WhiteSpaces) SetInt64

func (i *WhiteSpaces) SetInt64(in int64)

SetInt64 sets the WhiteSpaces value from an int64.

func (*WhiteSpaces) SetString

func (i *WhiteSpaces) SetString(s string) error

SetString sets the WhiteSpaces value from its string representation, and returns an error if the string is invalid.

func (WhiteSpaces) String

func (i WhiteSpaces) String() string

String returns the string representation of this WhiteSpaces value.

func (*WhiteSpaces) UnmarshalText

func (i *WhiteSpaces) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (WhiteSpaces) Values

func (i WhiteSpaces) Values() []enums.Enum

Values returns all possible values for the type WhiteSpaces.

Jump to

Keyboard shortcuts

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