richtext

package
v0.0.0-...-b6c76eb Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Align

type Align uint8
const (
	AlignLeftDumb Align = iota
	AlignLeft
	AlignRight
	AlignCenter
	AlignJustified
)

type Ctor

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

func (*Ctor) Align

func (ctor *Ctor) Align(align Align)

Align changes current text alignment. It is only legal to call Align before inserting text or after a newline character is inserted.

func (*Ctor) ClearStyle

func (ctor *Ctor) ClearStyle()

ClearStyle resets the text style to the default.

func (*Ctor) End

func (ctor *Ctor) End()

func (*Ctor) LastChunkSel

func (ctor *Ctor) LastChunkSel() Sel

LastChunkSel returns the selection for the last chunk added

func (ctor *Ctor) Link(text string, hoverColor color.RGBA, callback func()) bool

Link adds a link to the widget. It will return true if the link was clicked and callback is nil.

func (*Ctor) ParagraphStyle

func (ctor *Ctor) ParagraphStyle(align Align, color color.RGBA)

func (*Ctor) RestoreStyle

func (ctor *Ctor) RestoreStyle()

RestoreStyle restores the last saved text style.

func (*Ctor) SaveStyle

func (ctor *Ctor) SaveStyle()

SaveStyle saves the current text style.

func (*Ctor) SetAlignForSel

func (ctor *Ctor) SetAlignForSel(sel Sel, align Align)

SetAlignForSel changes the alignment for the specified region.

func (*Ctor) SetParagraphStyleForSel

func (ctor *Ctor) SetParagraphStyleForSel(sel Sel, align Align, color color.RGBA)

func (*Ctor) SetStyle

func (ctor *Ctor) SetStyle(s TextStyle)

SetStyle changes current text style. If color or selColor are the zero value the default value (copied from the window) will be used. If face is nil the default font face from the window style will be used.

func (*Ctor) SetStyleForSel

func (ctor *Ctor) SetStyleForSel(sel Sel, s TextStyle)

SetStyleForSel changes the text style for the specified region.

func (*Ctor) Text

func (ctor *Ctor) Text(text string)

Text adds text to the widget.

type Events

type Events uint8
const (
	Clicked Events = 1 << iota
	Active
)

type FaceFlags

type FaceFlags uint16
const (
	Underline FaceFlags = 1 << iota
	Strikethrough
)

type Flags

type Flags uint16
const (
	AutoWrap Flags = 1 << iota
	Selectable
	Clipboard
	ShowTick
	Keyboard // scrolling using keyboard
	MimicLabel
	Editable // supports editing
)

type RichText

type RichText struct {
	Sel   Sel // selected text if this widget is selectable, cursor position will have S == E
	Flags Flags

	SelFgColor color.RGBA              // foreground color for selection, zero value specifies that it should be copied from the window style
	SelColor   color.RGBA              // background color for selection, zero value specifies that it should be copied from the window style
	Width      int                     // maximum line width
	Events     Events                  // events that happened during current frame
	Group      *SelectionGroup         // selection group for this object, only one object in the group can have a selection
	Replace    func(Sel, *string) bool // if set and the Editable flag is set it will be called when the user wants to edit and should replace the specified selection with the given string
	// contains filtered or unexported fields
}

func New

func New(flags Flags) *RichText

func (*RichText) Append

func (rtxt *RichText) Append(scroll bool) *Ctor

Append allows adding text at the end of the widget. Calling Link or LinkBytes on the returned constructor is illegal if callback is nil. Selections for SetStyleForSel and SetAlignForSel are interpreted to be relative to the newly added text.

func (*RichText) FollowCursor

func (rtxt *RichText) FollowCursor()

func (*RichText) Get

func (rtxt *RichText) Get(sel Sel) string

func (*RichText) Len

func (rtxt *RichText) Len() int

Len returns the length in physical lines of rtxt

func (*RichText) Look

func (rtxt *RichText) Look(text string, wraparound bool) bool

Look searches from the next occurence of text inside rtxt, starting at rtxt.Sel.S. Restarts the search from the start if nothing is found.

func (*RichText) Rows

func (rtxt *RichText) Rows(w *nucular.Window, changed bool) *Ctor

Rows is like Widget but adds the contents as a series of rows instead of a single widget.

func (*RichText) Tail

func (rtxt *RichText) Tail(n int)

Tail removes everything but the last n physical lines

func (*RichText) Widget

func (rtxt *RichText) Widget(w *nucular.Window, changed bool) *Ctor

Widget adds this rich text widget as a widget to w. The returned constructor allows populating the rich text widget with text and responding to events. The constructor will be returned under this circumstances: 1. the first time this function or Rows is called 2. changed is true 3. a link was clicked

type Sel

type Sel struct {
	S, E int32
}

type SelectionGroup

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

type TextStyle

type TextStyle struct {
	Face   font.Face
	Cursor font.Cursor
	Flags  FaceFlags

	Color, SelFgColor, BgColor color.RGBA // foreground color, selected foreground color, background color

	LeftMarginHere bool // moves the left margin to this position, must be AlignLeft or AlignLeftDumb

	Tooltip      func(*nucular.Window)
	TooltipWidth int

	ContextMenu func(*nucular.Window)
}

Jump to

Keyboard shortcuts

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