text

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

package text provides contents holder cotaining plain-text, clickable-text-button, ... etc.

Index

Constants

View Source
const (
	AlignmentLeft   = Alignment(attr.AlignmentLeft)
	AlignmentCenter = Alignment(attr.AlignmentCenter)
	AlignmentRight  = Alignment(attr.AlignmentRight)
)
View Source
const DefaultMaxRuneWidth = 80

default size of max of rune width in Frame.

Variables

View Source
var (
	// Material White to draw text.
	DefaultForeColor = theme.DefaultPalette.Foreground().C.(color.RGBA)

	// Material LightBlue 400 to draw button text
	DefaultButtonColor = theme.DefaultPalette.Accent().C.(color.RGBA)

	// It is used to reset color setting.
	ResetColor = color.RGBA{}
)
View Source
var DefaultCachedImageSize = egimg.DefaultCacheSize

DefaultCachedImageSize is a default value for a cached image size.

Functions

func DrawingString

func DrawingString(v *View) string

return string cotent that will be shown by Draw().

func String

func String(f *Frame) string

return string entire content in the given Frame.

func StringFrom

func StringFrom(f *Frame, startP int32) string

return string cotent in the given Frame in range from startP to end.

Types

type Alignment

type Alignment int8

Alignment of current line. For convenience to not import attribute package, it is same as attribute.Alignment.

func (Alignment) String

func (a Alignment) String() string

type Box

type Box interface {
	RuneWidth(*Frame) int     // return box's width in runewidth.
	LineCountHint(*Frame) int // return box's line count hint, which is used optionally.

	// return next Box, if not found return nil
	Next(*Frame) Box
	Prev(*Frame) Box

	// draw its contents into font.Drawer.Dst.
	Draw(*font.Drawer, *View)
	// contains filtered or unexported methods
}

Box is abstract content. It is used in Frame internally, so you need not to implements it. The exported methods can be used to inspect it.

type ButtonBox added in v0.6.0

type ButtonBox interface {
	TextBox
	Command() string
}

type Editor

type Editor struct {
	Color color.RGBA
	// contains filtered or unexported fields
}

Editor edits Frame's contents. It only appends new content into Frame's last.

It is constructed by Frame.Editor(), not NewEditor() or Editor{}

Multiple Editors do not share their states.

func (*Editor) Close

func (e *Editor) Close()

close this editor. after this reference for Frame is invalid, so calling any Editor's method will occur panic for nil reference.

func (*Editor) CurrentRuneWidth

func (e *Editor) CurrentRuneWidth() int

It returns runewidth in current editing Paragraph and Line, which must be last of Frame. Returned width 0 indicates that this Paragraph/Line have empty contents, otherwise have some content in that width.

func (*Editor) DeleteAll

func (e *Editor) DeleteAll()

delete all contents in the Frame.

func (*Editor) DeleteLastParagraphs

func (e *Editor) DeleteLastParagraphs(n int)

delete n-1 last paragraphs of Frame and clear contents of 1 current line. if n is less than or equal to 0, do nothing..

func (*Editor) GetAlignment

func (e *Editor) GetAlignment() Alignment

get current Alignment of Paragraph.

func (*Editor) NewLineCount

func (e *Editor) NewLineCount() int

It returns count for outputting new line. return 0 at initial state.

func (*Editor) SetAlignment

func (e *Editor) SetAlignment(a Alignment)

set Alignment to the editor so that writing text is aligned.

func (*Editor) WriteButton

func (e *Editor) WriteButton(text, cmd string) (n int, err error)

write text as button into end of frame's text. button text does not accept "\n". It is not splitable as same as label.

func (*Editor) WriteImage added in v0.6.0

func (e *Editor) WriteImage(imgFile string, widthInRW, heightInLC int) (err error)

WriteImage writes image into text frame with size of widthInRW x heightInLC. widthInRW stands for width in Rune Width and stands for height in Line Count.

func (*Editor) WriteLabel

func (e *Editor) WriteLabel(text string) (n int, err error)

write text as label into end of frame's text. The lable text is truncated if including "\n" It is not splitable to remain continuity of content for showing screen.

func (*Editor) WriteLine

func (e *Editor) WriteLine(sym string) (n int, err error)

Write line into end of frame. The line must place end of frame's line. That is, after this, writing frame's line moves to next.

func (*Editor) WriteSpace added in v0.9.0

func (e *Editor) WriteSpace(widthInRW int) (err error)

func (*Editor) WriteText

func (e *Editor) WriteText(s string) (n int, err error)

write text into end of frame's text.

type Frame

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

represents view contents, which contains text and image.

referenced to golang.org/exp/shiny/text/text.go

func NewFrame

func NewFrame(opt *FrameOptions) *Frame

func (*Frame) Editor

func (f *Frame) Editor() *Editor

return Editor to edit frame content.

func (*Frame) FirstParagraph

func (f *Frame) FirstParagraph() *Paragraph

returns the first paragraph of this frame.

func (*Frame) Height

func (f *Frame) Height() int

Height returns the height in pixels of this Frame.

func (*Frame) Len

func (f *Frame) Len() int

Len returns the number of bytes in the Frame's text.

func (*Frame) LineCount

func (f *Frame) LineCount() int

LineCount returns the number of Lines in this Frame.

This count includes any soft returns inserted to wrap text to the maxWidth.

func (*Frame) ParagraphCount

func (f *Frame) ParagraphCount() int

ParagraphCount returns the number of Paragraphs in this Frame.

This count excludes any soft returns inserted to wrap text to the maxWidth.

func (*Frame) SetFace

func (f *Frame) SetFace(face font.Face)

SetFace sets the font face for measuring text.

func (*Frame) SetMaxRuneWidth

func (f *Frame) SetMaxRuneWidth(rwidth int)

SetMaxRuneWidth sets the target maximum width of a Line of content, as a runewidth which is measured as: singlebyte: 1, multibyte:2. Contents will be broken so that a Line's width is less than or equal to this maximum width.

If passed argument is less than or equal 1, it treats as default size 80.

func (*Frame) View

func (f *Frame) View() *View

return View to view frame content.

type FrameOptions

type FrameOptions struct {
	// The max range of Frame's contents.
	MaxParagraphs, MaxParagraphBytes int32
}

type ImageBox added in v0.6.0

type ImageBox interface {
	// ImageBox's text content may be a debug information.
	// RuneWidth and LineCountHint shows image size in text scale.
	TextBox
	// SourceImage returns source path for image content. The byte
	// content of image is not included.
	SourceImage() string
}

ImageBox holds image source and TextBox facility.

type Line

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

Line holds Boxes of contents.

func (*Line) FirstBox

func (l *Line) FirstBox(f *Frame) Box

return first Box. if not found return nil, indicating the line has no contents.

func (*Line) Height

func (l *Line) Height(f *Frame) int

Height returns the height in pixels of this Line.

func (*Line) Next

func (l *Line) Next(f *Frame) *Line

return next Line. if not found return nil.

func (*Line) Prev

func (l *Line) Prev(f *Frame) *Line

return prev Line. if not found return nil.

func (*Line) RuneWidth

func (l *Line) RuneWidth(f *Frame) int

it returns sum of runewidth of all Boxes in the Line.

type LineBox added in v0.6.0

type LineBox interface {
	Text(*Frame) string
	Symbol() string
	FgColor() color.RGBA
}

type Paragraph

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

Paragraph holds Lines of text.

Here, Paragraph is treated as actual Line. Its internal Lines are treated as layouted lines, which are adjust to Frame's max width.

func (*Paragraph) FirstLine

func (p *Paragraph) FirstLine(f *Frame) *Line

FirstLine returns the first Line of this Paragraph.

f is the Frame that contains the Paragraph.

func (*Paragraph) Height

func (p *Paragraph) Height(f *Frame) int

Height returns the height in pixels of this Paragraph.

func (*Paragraph) LineCount

func (p *Paragraph) LineCount(f *Frame) int

LineCount returns the number of Lines in this Paragraph.

This count includes any soft returns inserted to wrap text to the maxWidth.

func (*Paragraph) Next

func (p *Paragraph) Next(f *Frame) *Paragraph

Next returns the next Paragraph after this one in the Frame.

f is the Frame that contains the Paragraph.

func (*Paragraph) Prev

func (p *Paragraph) Prev(f *Frame) *Paragraph

type SpaceBox added in v0.9.0

type SpaceBox interface {
	TextBox

	SpaceRuneWidth() int
}

space box is alsmost same as labelBox, is non splitable, but does not contain any content. It is used for spacing with runeWidth and lineCount=1 for the area and used for complex layout. The difference from lableBox with multile space character " " is that there is no drawing at the area while the labelBox with space draws space characters, means filling the area by font color. For example, suppose [Space] is space box and others are text box then view area will be shown as like below. >> Some text... >> [Space]Indented Some text... >> Some text...[Space]Trailing text...

type TextBox

type TextBox interface {
	Text(*Frame) string
	Bytes(*Frame) []byte
	FgColor() color.RGBA
	// contains filtered or unexported methods
}

TextBox holds text and can show it for user.

type TextScaleImageLoader added in v0.6.0

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

TextScaleImageLoader is image loader which accepts text scale image size, such as rune width and line count for loading options. The loaded image is cached internally.

func NewTextScaleImageLoader added in v0.6.0

func NewTextScaleImageLoader(cachedImageSize int, fontHeight, fontSingleWidth fixed.Int26_6) *TextScaleImageLoader

NewTextScaleImageLoader create new instance.

func (*TextScaleImageLoader) CalcImageSize added in v0.6.0

func (l *TextScaleImageLoader) CalcImageSize(resizedWidthInRW, resizedHeightInLC int) image.Point

CalcImageSize converts text scale size into pixel scale size by using pixel scale size of the font.

func (*TextScaleImageLoader) FontHeight added in v0.6.0

func (l *TextScaleImageLoader) FontHeight() fixed.Int26_6

func (*TextScaleImageLoader) FontSingleWidth added in v0.6.0

func (l *TextScaleImageLoader) FontSingleWidth() fixed.Int26_6

func (*TextScaleImageLoader) GetResized added in v0.6.0

func (l *TextScaleImageLoader) GetResized(file string, resizedWidthInRW, resizedHeightInLC int) (image.Image, TextScaleSize, error)

GetResized get resized image and text-scaled image size from image loader. The result is cached for combination of the arguments. If both of resizedXXX is zero, the result is not resized. If either of resizedXXX is zero, the resized size of that is auto-filled by the other with keep aspect ratio of original image size.

type TextScaleSize added in v0.6.0

type TextScaleSize struct {
	Width  int
	Height int
}

TextScaleSize is size represented by text-scale rune width and line count.

type View

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

View is view of Frame, which controls how to show Frame to user and comminucates any user event for changing view state.

View is constructed by Frame.NewView(), not NewView() or View{}.

func (*View) Draw

func (v *View) Draw(m *image.RGBA, origin image.Point)

func (*View) FindCommand

func (v *View) FindCommand(p image.Point) (string, bool)

find command on position p in pixel. because stored commands are in phisical screen coordinate space, it requires point p in phisical screen coordinate space. return command and whether command is found?

func (*View) GetImage added in v0.6.0

func (v *View) GetImage(file string, resizedWidthInRW, resizedHeightInLC int) (image.Image, fixed.Point26_6, bool)

GetImage returns image and its size in fixed-point from view's repository. The third returned value indicates whether image is successfully loaded or not. A image is specified by file path and its load options. It returns loaded image if file and options matches repository or returns fallback image if file and options does not match. So it never returns empty nor nil image.

func (*View) HighlightCommand

func (v *View) HighlightCommand(p image.Point) bool

Highlight command which is selected on the position p because stored commands are in phisical screen coordinate space, it requires point p in phisical screen coordinate space. in View's coordinate space. return that command is found.

func (*View) LineCount

func (v *View) LineCount() int

It returns a count of visuallized lines in the max view height.

func (*View) MeasureTextScaleImageSize added in v0.6.0

func (v *View) MeasureTextScaleImageSize(file string, resizedWidthInRW, resizedHeightInLC int) (TextScaleSize, error)

MeasureTextScaleImageSize returns image size in text scale specified by file, resized width and height. This function's arguments are same as GetImage() and should returned consistent result.

func (*View) RuneWidth

func (v *View) RuneWidth() int

It returns max runewidth in the max view width, indicating how many charancters are in view's width. Note that single-byte character is counted as 1 and multibyte is typically as 2.

func (*View) Scroll

func (v *View) Scroll(moveY int)

vertiacal scrolling of view port of Frame contents. moveY is size of y move in pixel. positive moveY corresponds to scroll up and otherwise scroll down. 0 value corresponds to stop scroll.

func (*View) ScrollLine

func (v *View) ScrollLine(n int)

scroll n lines. positive n corresponds to scroll up, otherwise down.

func (*View) ScrolledLinePos added in v0.7.0

func (v *View) ScrolledLinePos() (pos int)

ScrolledLinePos returns curretnly visualized line position in all lines stored in the frame. The line position takes in range [0:(StoredLineCount()-LineCount())], 0 means most top of lines and (StoredLineCount()-LineCount()) means most bottom of the lines. Note that line pos indicates top of currently visualized lines, so ScrolledLinePos of the most bottom should be substracted from LineCount() which returns visualized line count. The line position is differed by every scrolling.

func (*View) SetFace

func (v *View) SetFace(face font.Face) error

Set font face which must be monospace. if font is not monospace return error. It changes Frame layout.

func (*View) SetSize

func (v *View) SetSize(size image.Point)

Set View size in pixel. It changes Frame layout.

func (*View) StoredLineCount added in v0.7.0

func (v *View) StoredLineCount() (nline int)

It returns a count of all lines stored in the frame, which includig not visialized one. This is equivalent to the frame.LineCount() but user should use this since this is goroutine safe.

func (*View) UnhighlightCommand

func (v *View) UnhighlightCommand() bool

Unhighlight all the command in View. return highlighted button exist and is Unhighlighted.

Directories

Path Synopsis
package pubdata intended for exporting data structure for other platforms such as mobile, wasm and so on.
package pubdata intended for exporting data structure for other platforms such as mobile, wasm and so on.
mock
Package mock_publisher is a generated GoMock package.
Package mock_publisher is a generated GoMock package.

Jump to

Keyboard shortcuts

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