zedit

package module
v0.0.0-...-d27ce1b Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 30 Imported by: 2

README

Zedit for Fyne

GoDoc Go Report Card

Zedit is a helper widget for Fyne to implement an efficient single-font text editor with syntax coloring. This package is in alpha stage and not yet usable. It contains many hacks and changes a lot. If you find it interesting, you need to wait for a release. However, please feel free to study the source code and let me know if you find a bug.

Documentation

Index

Constants

View Source
const MAGIC = 86637303 // magic cookie
View Source
const MINVERSION = 100 // minimum required version
View Source
const VERSION = 100 // this version 100 == "v1.0.0"

Variables

View Source
var EmptyStyle = Style{}
View Source
var ErrInvalidStream = fmt.Errorf("invalid input text format")
View Source
var ErrTooLongLine = fmt.Errorf("a line in the input text was too large")
View Source
var ErrTooManyLines = fmt.Errorf("too many lines, the input text could not be read because it is too large")
View Source
var ErrTooManyTags = fmt.Errorf("the input text has too many tags")
View Source
var ErrVersionTooLow = fmt.Errorf("this software's version for input text reading is outdated and cannot read the provided text")

Functions

func BlendColors

func BlendColors(blending BlendMode, switched bool, c1, c2 color.Color) color.Color

func CmpPos

func CmpPos(a, b CharPos) int

CmpPos lexicographically compares to char positions and returns -1 if a is before b, 0 if a and b are equal positions, and 1 if a is after b. This is used for interval operation.

func GetKeyboardShortcutKey

func GetKeyboardShortcutKey(s fyne.KeyboardShortcut) string

GetKeyboardShortcutKey makes a lookup key for a fyne.KeyboardShortcut that is equal for any two shortcuts with the same key and modifier. (The shortcut name does not have this property.)

func GradientColor

func GradientColor(c1, c2 color.Color, t float64) color.Color

func IsLeftParen

func IsLeftParen(c rune) bool

IsParen returns true if the rune is a left paren.

func IsQuotationMark

func IsQuotationMark(c rune) bool

IsQuotationMark returns true if the rune is a quotation mark, which behaves similar to a paren but is symmetric (i.e., opening and closing marks are identical).

func IsRightParen

func IsRightParen(c rune) bool

IsRightParen returns true if the rune is a right paren.

func SafePositiveValue

func SafePositiveValue(value int, maximum int) int

SafePositiveValue returns a sanitized integer that is 0 or larger and no larger than the given maximum value (inclusive).

Types

type BlendMode

type BlendMode int
const (
	BlendColor BlendMode = iota + 1
	BlendColorBurn
	BlendColorDodge
	BlendDarken
	BlendDarkerColor
	BlendDifference
	BlendDivide
	BlendExclusion
	BlendHardLight
	BlendHardMix
	BlendHue
	BlendLighten
	BlendLighterColor
	BlendLinearBurn
	BlendLinearDodge
	BlendLinearLight
	BlendLuminosity
	BlendMultiply
	BlendOverlay
	BlendPhoenix
	BlendPinLight
	BlendReflex
	BlendSaturation
	BlendScreen
	BlendSoftLight
	BlendSubstract
	BlendVividLight
)

type CaretMovement

type CaretMovement int
const (
	CaretDown CaretMovement = iota + 1
	CaretUp
	CaretLeft
	CaretRight
	CaretHome
	CaretEnd
	CaretLineStart
	CaretLineEnd
	CaretHalfPageDown
	CaretHalfPageUp
	CaretPageDown
	CaretPageUp
)

type Cell

type Cell struct {
	Rune  rune
	Style Style
}

func NewCellFromTextGridCell

func NewCellFromTextGridCell(cell widget.TextGridCell) Cell

func (Cell) ToTextGridCell

func (c Cell) ToTextGridCell() widget.TextGridCell

type CharInterval

type CharInterval struct {
	Start CharPos
	End   CharPos
}

func (CharInterval) Contains

func (c CharInterval) Contains(pos CharPos) bool

Contains returns true if the char interval contains the given position, false otherwise.

func (CharInterval) Lines

func (c CharInterval) Lines() int

Lines returns the number of lines this interval spans, including start and end line.

func (CharInterval) MaybeSwap

func (c CharInterval) MaybeSwap() CharInterval

MaybeSwap compares the start and the end, and if the end is before the start returns the interval where the end is the start and the start is the end. The function returns the unchanged interval otherwise.

func (CharInterval) OutsideOf

func (c1 CharInterval) OutsideOf(c2 CharInterval) bool

OutsideOf returns true if c1 is outside of c2.

func (CharInterval) Overlapping

func (c1 CharInterval) Overlapping(c2 CharInterval) bool

Overlapping returns true if the char interval is overlapping in any way with the interval passed as argument, flase otherwise. c1.Overlapping(c2) and c2.Overlapping(c1) are equivalent.

func (CharInterval) Sanitize

func (c CharInterval) Sanitize(lastPos CharPos) CharInterval

Sanitize computes a new interval that is strictly between [(0,0)...lastPos]. This can be used as a helper when intervals might have invalid values (e.g. due to user input). Sanitize calls MaybeSwap.

type CharPos

type CharPos struct {
	Line         int
	Column       int
	IsLineNumber bool
}

CharPos represents a character position in the grid. If IsLineNumber is true, then the position is in the line number display, Line contains the line number, and Column is 0. Otherwise, Line and Column contain the line, column pair of the grid closest to the position.

func MaxPos

func MaxPos(a, b CharPos) CharPos

func MinPos

func MinPos(a, b CharPos) CharPos

type Config

type Config struct {
	SelectionTag         Tag             // the tag used for marking selection ranges
	SelectionStyler      TagStyler       // style of the selection tag
	HighlightTag         Tag             // for transient highlighting (usually has a different style than selection)
	HighlightStyler      TagStyler       // style func for highlight
	MarkTag              Tag             // template for the mark tags
	MarkTags             []Tag           // a number of pre-configured tags used for marking text (default: 0..9 tags)
	MarkStyler           TagStyler       // mark style func, using the tag index to distinguish marks
	ErrorTag             Tag             // for errors
	ParenErrorTag        Tag             // for wrong right parenthesis
	ErrorStyler          TagStyler       // style of errors (default: theme error color)
	ShowLineNumbers      bool            // switches on or off the line number display, which is in a separate grid
	ShowWhitespace       bool            // show special glyphs for line endings (currently defunct)
	BlendFG              BlendMode       // how layers of color are blended/composited for text foreground
	BlendFGSwitched      bool            // whether to switch the colors while blending forground (sometimes makes a difference)
	BlendBG              BlendMode       // how layers of color are blended for background
	BlendBGSwitched      bool            // whether the colors are switched while blending background colors (sometimes makes a difference)
	HardLF               rune            // hard line feed character
	SoftLF               rune            // soft line feed character (subject to word-wrapping and deletion in text)
	ScrollFactor         float32         // speed of scrolling
	TabWidth             int             // If set to 0 the fyne.DefaultTabWidth is used
	MinRefreshInterval   time.Duration   // minimum interval in ms to refresh display
	CharDrift            float32         // default 0.4, added to calculation per char when finding char position from x-position
	LineWrap             bool            // automatically wrap lines (default: true)
	SoftWrap             bool            // soft wrap lines, if not true wrapping inserst hard line feeds (default: true)
	HighlightParens      bool            // highlight parentheses and quotation marks (default: true)
	HighlightParenRange  bool            // highlight the whole range between matching parens (default: false)
	DrawCaret            bool            // if true, the caret is drawn, if false, the caret is handled but not drawn
	CaretBlinkDelay      time.Duration   // period after last interaction before caret starts blinking
	CaretOnDuration      time.Duration   // how long the caret is shown when blinking
	CaretOffDuration     time.Duration   // how long a blinking caret is off
	ParagraphLineNumbers bool            // line numbers are based on paragraphs to take into account soft wrap
	TagPreWrite          TagPreWriteFunc // called before a tag is written
	TagPostRead          TagPostReadFunc // called after a tag has been read, may be used to re-store callback
	CustomLoader         CustomLoadFunc  // called during Load after the editor has loaded everything else
	CustomSaver          CustomSaveFunc  // called after during Save everything else has been saved
	MaxLines             int64           // maximum number of lines (if 0 or below, no limit) only used during Load
	MaxColumn            int64           // maximum column length (if 0 or below, no limit) only used during Load
	MaxTags              int64           // maximum number of tags (if 0 or below, no limit) only used during Load
	MaxPrintLines        int             // maximum number of lines for printing for console mode, preceding lines are cut off
}

Config stores configuration information for an editor.

func NewConfig

func NewConfig() *Config

NewConfig returns a new config with default values.

type CustomLoadFunc

type CustomLoadFunc func(dec *json.Decoder) error // used for reading custom data during Load()

type CustomSaveFunc

type CustomSaveFunc func(enc *json.Encoder) error // used for writing custom data during Save()

type CustomTagUnmarshallerFunc

type CustomTagUnmarshallerFunc func(typeName string, in []byte) (Tag, error)
var CustomTagUnmarshaller CustomTagUnmarshallerFunc

CustomTagUnmarshaller should be set to a function that takes the type name and []byte, and returns the appropriate custom Tag based on how MarshalJSON is implemented for that tag. The unmarshaller for all tags will automatically dispatch to this function when unmarshalling a custom tag implemented by the user of this package. This is a bit safer and more flexible than trying to do this automatically using reflection.

type Editor

type Editor struct {
	widget.BaseWidget
	Lines   int             // the number of lines displayed
	Columns int             // the number of columns displayed
	Rows    [][]rune        // the text
	Tags    *TagContainer   // all tags
	Styles  *StyleContainer // styles associated with tags
	Config  *Config         // editor configuration
	// contains filtered or unexported fields
}

Editor is the main editor widget. Even though some of its properties are public, this is merely for convenience and it's best to only modify it using methods. If there is no method for some operation, chances are high that direct manipulation of internals such as editor.Rows might break in the future.

func NewEditor

func NewEditor(columns, lines int, c fyne.Canvas) *Editor

NewEditor returns a new editor widget with fixed columns and lines, which is displayed in the given canvas object. The editor has default configuration.

func NewEditorWithConfig

func NewEditorWithConfig(columns, lines int, c fyne.Canvas, config *Config) *Editor

NewEditorWithConfig returns a new editor with fixed columns and lines, which is displayed in the given canvas and uses the given configuration. The Config must be obtained by NewConfig() to ensure all defaults are initialized but may be changed before calling this function.

func (*Editor) AddEmacsShortcuts

func (z *Editor) AddEmacsShortcuts()

AddEmacsShortcuts adds some (very basic) Emacs shortcuts but some with Super key as modifier instead of Ctrl in order not to interfere with standard platform keyboard shortcuts.

func (*Editor) AddKeyHandler

func (z *Editor) AddKeyHandler(key fyne.KeyName, handler func(z *Editor))

AddKeyHandler adds a direct handler for the given key. Unlike AddShortcutHandler, a key handler is called whenever the key is pressed, even when no modifier is used.

func (*Editor) AddShortcutHandler

func (z *Editor) AddShortcutHandler(s fyne.KeyboardShortcut, handler func(z *Editor))

AddhortcutHandler adds a keyboard shortcut to the grid.

func (*Editor) Backspace

func (z *Editor) Backspace()

Backspace deletes the character left of the caret, if there is one.

func (*Editor) BlinkCaret

func (z *Editor) BlinkCaret(on bool)

BlinkCursor starts blinking the cursor or stops the cursor from blinking.

func (*Editor) CaretOff

func (z *Editor) CaretOff() bool

CaretOff switches the caret off temporarily. It returns true was blinking.

func (*Editor) CaretOn

func (z *Editor) CaretOn(blinking bool)

CaretOn switches the caret on again after it has been switched off.

func (*Editor) CenterLineOnCaret

func (z *Editor) CenterLineOnCaret()

CenterLineOnCaret adjusts the displayed lines such that the caret is in the center of the grid.

func (*Editor) CharAt

func (z *Editor) CharAt(pos CharPos) (rune, bool)

CharAt returns the unicode glyph at the given position.

func (*Editor) CreateRenderer

func (s *Editor) CreateRenderer() fyne.WidgetRenderer

func (*Editor) CurrentSelection

func (z *Editor) CurrentSelection() (CharInterval, bool)

CurrentSelection returns the CharInterval if there is a non-empty selection marked, an empty CharInterval and false otherwise.

func (*Editor) Cursor

func (z *Editor) Cursor() desktop.Cursor

func (*Editor) Cut

func (z *Editor) Cut()

Cut removes the selection text and corresponding tags.

func (*Editor) Delete

func (z *Editor) Delete(fromTo CharInterval)

Delete deletes a range of characters, optionally soft wrapping the paragraph with given hardLF and softLF runes as hard and soft line feed characters.

func (*Editor) Delete1

func (z *Editor) Delete1()

Delete1 deletes the character under the caret or the selection, if there is one.

func (*Editor) DoubleTapped

func (z *Editor) DoubleTapped(evt *fyne.PointEvent)

func (*Editor) DragEnd

func (z *Editor) DragEnd()

func (*Editor) Dragged

func (z *Editor) Dragged(evt *fyne.DragEvent)

func (*Editor) FindParagraphEnd

func (grid *Editor) FindParagraphEnd(row int, lf rune) int

FindParagraphEnd finds the end row of the paragraph in which row is located. If row is the last row, then it is returned. Otherwise, it checks for the next row that ends in lf (which may be the row with which this method was called).

func (*Editor) FindParagraphStart

func (z *Editor) FindParagraphStart(row int, lf rune) int

FindParagraphStart finds the start row of the paragraph in which row is located. If the row is 0, 0 is returned, otherwise this checks for the next line ending with lf and returns the row after it.

func (*Editor) FindRune

func (z *Editor) FindRune(pos CharPos, backward bool, searchFunc func(c rune) bool) (CharPos, bool)

FindRune searches one rune forward or backward, using searchFunc and returns the matching rune's position and true, or (0,0) and false. pos is included in the search.

func (*Editor) Focus

func (z *Editor) Focus()

Focus sets focus to the editor.

func (*Editor) FocusGained

func (z *Editor) FocusGained()

FocusGained implements a Focusable.

func (*Editor) FocusLost

func (z *Editor) FocusLost()

FocusLost implements a Focusable.

func (*Editor) GetCaret

func (z *Editor) GetCaret() CharPos

GetCaret returns the current caret position.

func (*Editor) GetLineText

func (z *Editor) GetLineText(row int) string

GetLineText obtains the text of a single line. The empty string is returned if there is no valid line.

func (*Editor) GetText

func (z *Editor) GetText() string

GetText returns the text of the whole editor as a unicode string.

func (*Editor) HasBlinkingCaret

func (z *Editor) HasBlinkingCaret() bool

HasBlinkingCaret returns true if the input cursor is blinking, false otherwise. use BlinkCursor to switch blinking on or off.

func (*Editor) Highlight

func (z *Editor) Highlight(interval CharInterval)

Highlight highlights a char interval using the default highlight tag and style. This method does not remove any previous highlights.

func (*Editor) Insert

func (z *Editor) Insert(r []rune, pos CharPos)

Insert inserts an array of TextGridCells at row, col, optionally soft wrapping it and using hardLF and softLF as hard and soft line feed characters. The cursor position and tags are updated automatically by this method.

func (*Editor) LastColumn

func (z *Editor) LastColumn(n int) int

LastColumn returns the last column of the given line (both 0-indexed).

func (*Editor) LastLine

func (z *Editor) LastLine() int

LastLine returns the last line (0-indexed).

func (*Editor) LastPos

func (z *Editor) LastPos() CharPos

LastPos returns the last char position in the buffer.

func (*Editor) LineText

func (z *Editor) LineText(i int) string

LineText returns the text of line i, the empty string if i is out of bounds.

func (*Editor) LineToPara

func (z *Editor) LineToPara(row int) (int, bool)

LineToPara returns the real paragraph number for a given 0-indexed row if there is one, false otherwise. The paragraph number is measured according to the hard LFs from the start of the document. If z.WordWrap is false, this function always returns the line + 1. However, if it is true, this function computes the paragraph number (indexed from 1) at the given line. This function is O(n) in the number of lines.

func (*Editor) Load

func (z *Editor) Load(in io.Reader) error

Load loads the contents into the editor.

func (*Editor) LoadFromFile

func (z *Editor) LoadFromFile(filepath string) error

LoadFromFile loads the editor contents from the given file.

func (*Editor) LoadMiscDataFromFile

func (z *Editor) LoadMiscDataFromFile(filepath string) error

LoadMiscDataFromFile loads the miscellaneous data and tags from the file. It's important to first load the text and then call this function, since it sets cursor and tags to values that assume the text is present.

func (*Editor) LoadText

func (z *Editor) LoadText(in io.Reader) error

LoadText loads a UTF8 text from an input stream.

func (*Editor) LoadTextFromFile

func (z *Editor) LoadTextFromFile(filepath string) error

LoadTextFromFile loads unicode text from the given file.

func (*Editor) MarkErrorParen

func (z *Editor) MarkErrorParen(interval CharInterval)

MarkError marks an error at a given range or removes it. Any existing error in the interval is removed. This is a quick and dirty solution. For full syntax coloring, it may be better to use a custom function instead of this one.

func (*Editor) MinSize

func (z *Editor) MinSize() fyne.Size

func (*Editor) MouseIn

func (z *Editor) MouseIn(evt *desktop.MouseEvent)

func (*Editor) MouseMoved

func (z *Editor) MouseMoved(evt *desktop.MouseEvent)

func (*Editor) MouseOut

func (z *Editor) MouseOut()

func (*Editor) MoveCaret

func (z *Editor) MoveCaret(dir CaretMovement)

MoveCaret moves the caret according to the given movement direction, which may be one of CaretUp, CaretDown, CaretLeft, and CaretRight.

func (*Editor) NextPos

func (z *Editor) NextPos(pos CharPos) (CharPos, bool)

NextPos returns the next char position in the grid and true, or the last position and false if there is no more.

func (*Editor) ParaCount

func (z *Editor) ParaCount() int

ParaCount counts the number of paragraphs, which is equivalent to the number of lines ending in HardLF + 1.

func (*Editor) ParaToLine

func (z *Editor) ParaToLine(paraNum int) (int, bool)

ParaToLine returns the 0-indexed line number at which the given 1-index n-th paragraph starts and true if there is a paragraph with that index, 0 and false otherwise. This function is O(n) in the number of lines.

func (*Editor) PosToCharPos

func (z *Editor) PosToCharPos(pos fyne.Position) CharPos

PosToCharPos converts an internal position of the widget in Fyne's pixel unit to a line, row pair.

func (*Editor) PrevPos

func (z *Editor) PrevPos(pos CharPos) (CharPos, bool)

PrevPos returns the previous char position in the grid and true, or 0, 0 and false if at home position.

func (*Editor) Print

func (z *Editor) Print(s string, tags []Tag)

Print prints a string at the current cursor position, advancing the cursor and applying the given tags to the string. The string may have multiple lines. This method is for console mode applications and should not be used for user editing. If config.MaxPrintLines is exceeded, lines are cut off at the beginning of the buffer.

func (*Editor) Refresh

func (z *Editor) Refresh()

func (*Editor) RemoveKeyHandler

func (z *Editor) RemoveKeyHandler(key fyne.KeyName)

RemoveKeyHandler removes the handler for the given key.

func (*Editor) RemoveSelection

func (z *Editor) RemoveSelection()

RemoveSelection removes the current selection, both the range returned by GetSelection and its graphical display.

func (*Editor) RemoveShortcutHandler

func (z *Editor) RemoveShortcutHandler(s string)

RemoveShortcutHandler removes the keyboard shortcut handler with the given key.

func (*Editor) Return

func (z *Editor) Return()

Return implements the return key behavior, which creates a new line and advances the caret accordingly.

func (*Editor) Save

func (z *Editor) Save(out io.Writer) error

Save the contents of the editor.

func (*Editor) SaveMiscDataToFile

func (z *Editor) SaveMiscDataToFile(filepath string) error

SaveMiscDataToFile saves tags and miscellaneous data to the given file. This can be used instead of SaveToFile if plaintext unicode file and miscellaneous data are supposed to be stored separately.

func (*Editor) SaveTextToFile

func (z *Editor) SaveTextToFile(filepath string) error

SaveTextToFile saves the text as unicode to a file. Nothing else beside the text is saved.

func (*Editor) SaveToFile

func (z *Editor) SaveToFile(filepath string) error

SaveToFile saves the editor's content to a file.

func (*Editor) ScrollDown

func (z *Editor) ScrollDown()

ScrollDown scrolls down the editor's line display by one line.

func (*Editor) ScrollLeft

func (z *Editor) ScrollLeft(n int)

ScrollLeft scrolls to the left by n chars or until the first char if n is too large.

func (*Editor) ScrollRight

func (z *Editor) ScrollRight(n int)

ScrollRight scrolls to the right by n chars but keeps some chars in display if n higher than the line.

func (*Editor) ScrollUp

func (z *Editor) ScrollUp()

ScrollUp scrolls up the editor's line display by one line.

func (*Editor) Scrolled

func (z *Editor) Scrolled(evt *fyne.ScrollEvent)

func (*Editor) Select

func (z *Editor) Select(fromTo CharInterval)

Select the given char interval. The interval is sanitized before setting the selection.

func (*Editor) SelectAll

func (z *Editor) SelectAll()

SelectAll selects all text in the editor.

func (*Editor) SelectWord

func (z *Editor) SelectWord(pos CharPos)

SelectWord selects the word under pos if there is one, removes the selection in any case.

func (*Editor) SetCaret

func (z *Editor) SetCaret(pos CharPos)

SetCaret sets the current caret position, taking care of paren highlighting and caret events but without scrolling or refreshing the display.

func (*Editor) SetLine

func (z *Editor) SetLine(row int, content []rune)

SetLine sets the line text. If row is beyond the current size, empty rows are added accordingly.

func (*Editor) SetLineNumberStyle

func (z *Editor) SetLineNumberStyle(style Style)

SetLineNumberStyle sets the style of the line number display in terms of an EditorStyle.

func (*Editor) SetMark

func (z *Editor) SetMark(n int)

SetMark marks a region. The given number must be a valid mark tag index.

func (*Editor) SetRune

func (z *Editor) SetRune(pos CharPos, r rune)

SetRune sets the rune at the given line and column.

func (*Editor) SetText

func (z *Editor) SetText(s string)

SetText sets the text in the editor to the given string, removing all tags in the process.

func (*Editor) SetTopLine

func (z *Editor) SetTopLine(x int)

SetTopLine sets the editor to display starting with the given line number.

func (*Editor) Tapped

func (z *Editor) Tapped(evt *fyne.PointEvent)

func (*Editor) Text

func (z *Editor) Text() string

Text returns the Editor's text as string. Both soft and hard linefeeds are replaced with rune '\n'.

func (*Editor) ToEnd

func (z *Editor) ToEnd(start CharPos) CharInterval

ToEnd returns the char interval from the given position to the last char of the buffer.

func (*Editor) TypedKey

func (z *Editor) TypedKey(evt *fyne.KeyEvent)

func (*Editor) TypedRune

func (z *Editor) TypedRune(r rune)

func (*Editor) TypedShortcut

func (z *Editor) TypedShortcut(s fyne.Shortcut)

func (*Editor) WordWrapRows

func (z *Editor) WordWrapRows(rows [][]rune, wrapCol int,
	softWrap bool, hardLF, softLF rune, cursorRow, cursorCol, startRow int,
	tags []Tag, pos CharPos) ([][]rune, int, int)

WordWrapRows word wraps a number of rows, making sure soft line breaks are adjusted and removed accordingly. The number of rows returned may be larger than the number of rows provided as an argument. The position of the original cursor row and column is returned.

type FixedSpacer

type FixedSpacer struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

FixedSpacer is a fyne widget that can be used a fixed-size dummy element that is not displayed. This is used in a hack to make an invisible widget for the scrollbar of the size of the number of rows in the editor widget, which is fixed size internally and only changes the display of lines when they are scrolled in and out of the view.

func NewFixedSpacer

func NewFixedSpacer(size fyne.Size) *FixedSpacer

NewFixedSpacer creates a spacer of the given fized size. It will not change its size except when ChangeSize is called.

func (*FixedSpacer) ChangeSize

func (s *FixedSpacer) ChangeSize(size fyne.Size)

ChangeSize can be used to change the spacer's size, so it reports this size to widgets that embed it such as the scrollbar.

func (*FixedSpacer) CreateRenderer

func (s *FixedSpacer) CreateRenderer() fyne.WidgetRenderer

CreateRenderer creates the fixed spacer renderer.

func (*FixedSpacer) MinSize

func (s *FixedSpacer) MinSize() fyne.Size

MinSize returns the minimum size of the spacer, which is the same as its size.

func (*FixedSpacer) SetHeight

func (s *FixedSpacer) SetHeight(height float32)

SetHeight sets the height of the spacer only. This is is used when the spacer is used as a dummy for a scrollbar.

func (*FixedSpacer) Size

func (s *FixedSpacer) Size() fyne.Size

Size returns the size of the spacer.

type FixedSpacerRenderer

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

FixedSpacerRenderer is a renderer for fixed spacer.

func (*FixedSpacerRenderer) Destroy

func (r *FixedSpacerRenderer) Destroy()

Destroy destroys the renderer.

func (*FixedSpacerRenderer) Layout

func (r *FixedSpacerRenderer) Layout(size fyne.Size)

Layout is the renderer layout procedure, which does nothing (a spacer is invisible).

func (*FixedSpacerRenderer) MinSize

func (r *FixedSpacerRenderer) MinSize() fyne.Size

MinSize returns the spacer's minimum size.

func (*FixedSpacerRenderer) Objects

func (r *FixedSpacerRenderer) Objects() []fyne.CanvasObject

Objects is needed for a renderer, but returns an empty array of CanvasObject for a spacer.

func (*FixedSpacerRenderer) Refresh

func (r *FixedSpacerRenderer) Refresh()

Refresh does nothing, since a fixed spacer is not displayed by itself.

type StandardTag

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

StandardTag is the default implementation of a Tag.

func NewTag

func NewTag(name string) *StandardTag

func NewTagWithUserData

func NewTagWithUserData(name string, index int, userData any) *StandardTag

func (*StandardTag) Callback

func (s *StandardTag) Callback() TagFunc

func (*StandardTag) Clone

func (s *StandardTag) Clone(newIndex int) Tag

func (*StandardTag) Index

func (s *StandardTag) Index() int

func (StandardTag) MarshalJSON

func (s StandardTag) MarshalJSON() ([]byte, error)

func (*StandardTag) Name

func (s *StandardTag) Name() string

func (*StandardTag) SetCallback

func (s *StandardTag) SetCallback(cb TagFunc)

func (*StandardTag) SetUserData

func (s *StandardTag) SetUserData(data any)

func (*StandardTag) UnmarshalJSON

func (s *StandardTag) UnmarshalJSON(data []byte) error

func (*StandardTag) UserData

func (s *StandardTag) UserData() any

type Style

type Style struct {
	FGColor, BGColor color.Color
}

func (Style) ToTextGridStyle

func (s Style) ToTextGridStyle() widget.TextGridStyle

type StyleContainer

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

StyleContainer holds a number of tag stylers. The data structure is threadsafe.

func NewStyleContainer

func NewStyleContainer() *StyleContainer

func (*StyleContainer) AddStyler

func (c *StyleContainer) AddStyler(styler TagStyler)

AddStyler adds a new tag styler to the style container.

func (*StyleContainer) RemoveStyler

func (c *StyleContainer) RemoveStyler(tag Tag)

RemoveStyler removes a tag styler from the container.

func (*StyleContainer) Stylers

func (c *StyleContainer) Stylers() []TagStyler

Stylers returns all tag stylers.

type Tag

type Tag interface {
	Name() string                    // return the tag's name, which is used for stylers
	Index() int                      // return the tag's new index, a serial number for tags with the same name
	Clone(newIndex int) Tag          // clone the tag, giving it a new index
	Callback() TagFunc               // called when TagEvents happen
	SetCallback(cb TagFunc)          // set the callback function
	UserData() any                   // optional payload
	SetUserData(data any)            // set optional payload
	MarshalJSON() ([]byte, error)    // for serialization
	UnmarshalJSON(data []byte) error // for deserialization
}

Tags are used to store information about the editor text associated with intervals. A tag's position is adjusted automatically as the editor text changes. Stylers can be associated to multiple tags with the same name.

type TagContainer

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

TagContainer is a container for holding tags and associating them with char intervals. The data structure is generally threadsafe but some methods can have race conditions and are documented as such.

func NewTagContainer

func NewTagContainer() *TagContainer

NewTagContainer returns a new empty tag container.

func (*TagContainer) Add

func (t *TagContainer) Add(interval CharInterval, tags ...Tag)

Add adds a number of tags and associates them with the given interval.

func (*TagContainer) AllTags

func (c *TagContainer) AllTags() []TagWithInterval

func (*TagContainer) Clear

func (t *TagContainer) Clear()

Clear deletes all tags in the container but retains stylers.

func (*TagContainer) CloneTag

func (t *TagContainer) CloneTag(tag Tag) Tag

CloneTag clones the given tag with a new index, and registers the tag in the container but without an associated interval. If there is no tag in the container, it registers the tag and returns it without cloning it.

func (*TagContainer) Delete

func (t *TagContainer) Delete(tag Tag) bool

Delete deletes the given tag, returns true if the tag was deleted, false if there was no such tag.

func (*TagContainer) DeleteByName

func (t *TagContainer) DeleteByName(name string) bool

DeleteByName deletes all tags with the given name. This method does not guarantee that tags that are added concurrently while it is executed are deleted. They may or may not be deleted. So, the method is not protected against race conditions. It is generally thread-safe, however.

func (*TagContainer) Lookup

func (t *TagContainer) Lookup(tag Tag) (CharInterval, bool)

Lookup returns the char interval associated with the given tag.

func (*TagContainer) LookupRange

func (t *TagContainer) LookupRange(interval CharInterval) ([]Tag, bool)

LookupRange returns the tags intersecting with the given char interval.

func (*TagContainer) SetAllTags

func (c *TagContainer) SetAllTags(tags []TagWithInterval)

func (*TagContainer) TagsByName

func (t *TagContainer) TagsByName(name string) (*orderedset.OrderedSet[Tag], bool)

TagsByName returns all tags with the given name. This is used when stylers are applied because these work on a by-name basis.

func (*TagContainer) Upsert

func (t *TagContainer) Upsert(tag Tag, interval CharInterval)

Upsert changes the interval associated with the given tag.

type TagEvent

type TagEvent int
const (
	CaretEnterEvent TagEvent = iota
	CaretLeaveEvent
)

type TagFunc

type TagFunc func(evt TagEvent, tag Tag, interval CharInterval)

type TagPostReadFunc

type TagPostReadFunc func(tag TagWithInterval) error // used after a tag has been read

type TagPreWriteFunc

type TagPreWriteFunc func(tag TagWithInterval) error // used before a tag is written

type TagStyleFunc

type TagStyleFunc func(tag Tag, c Cell) Cell

type TagStyler

type TagStyler struct {
	TagName      string
	StyleFunc    TagStyleFunc
	DrawFullLine bool
}

TagSyler styles tags with the given name.

type TagWithInterval

type TagWithInterval struct {
	Tag      Tag
	Interval CharInterval
}

TagWithInterval stores a tag and its accompanying interval.

func (TagWithInterval) MarshalJSON

func (t TagWithInterval) MarshalJSON() ([]byte, error)

func (*TagWithInterval) UnmarshalJSON

func (t *TagWithInterval) UnmarshalJSON(in []byte) error

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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