Documentation ¶
Overview ¶
package text provides contents holder cotaining plain-text, clickable-text-button, ... etc.
Index ¶
- Constants
- Variables
- func DrawingString(v *View) string
- func String(f *Frame) string
- func StringFrom(f *Frame, startP int32) string
- type Alignment
- type Box
- type ButtonBox
- type Editor
- func (e *Editor) Close()
- func (e *Editor) CurrentRuneWidth() int
- func (e *Editor) DeleteAll()
- func (e *Editor) DeleteLastParagraphs(n int)
- func (e *Editor) GetAlignment() Alignment
- func (e *Editor) NewLineCount() int
- func (e *Editor) SetAlignment(a Alignment)
- func (e *Editor) WriteButton(text, cmd string) (n int, err error)
- func (e *Editor) WriteImage(imgFile string, widthInRW, heightInLC int) (err error)
- func (e *Editor) WriteLabel(text string) (n int, err error)
- func (e *Editor) WriteLine(sym string) (n int, err error)
- func (e *Editor) WriteSpace(widthInRW int) (err error)
- func (e *Editor) WriteText(s string) (n int, err error)
- type Frame
- func (f *Frame) Editor() *Editor
- func (f *Frame) FirstParagraph() *Paragraph
- func (f *Frame) Height() int
- func (f *Frame) Len() int
- func (f *Frame) LineCount() int
- func (f *Frame) ParagraphCount() int
- func (f *Frame) SetFace(face font.Face)
- func (f *Frame) SetMaxRuneWidth(rwidth int)
- func (f *Frame) View() *View
- type FrameOptions
- type ImageBox
- type Line
- type LineBox
- type Paragraph
- type SpaceBox
- type TextBox
- type TextScaleImageLoader
- func (l *TextScaleImageLoader) CalcImageSize(resizedWidthInRW, resizedHeightInLC int) image.Point
- func (l *TextScaleImageLoader) FontHeight() fixed.Int26_6
- func (l *TextScaleImageLoader) FontSingleWidth() fixed.Int26_6
- func (l *TextScaleImageLoader) GetResized(file string, resizedWidthInRW, resizedHeightInLC int) (image.Image, TextScaleSize, error)
- type TextScaleSize
- type View
- func (v *View) Draw(m *image.RGBA, origin image.Point)
- func (v *View) FindCommand(p image.Point) (string, bool)
- func (v *View) GetImage(file string, resizedWidthInRW, resizedHeightInLC int) (image.Image, fixed.Point26_6, bool)
- func (v *View) HighlightCommand(p image.Point) bool
- func (v *View) LineCount() int
- func (v *View) MeasureTextScaleImageSize(file string, resizedWidthInRW, resizedHeightInLC int) (TextScaleSize, error)
- func (v *View) RuneWidth() int
- func (v *View) Scroll(moveY int)
- func (v *View) ScrollLine(n int)
- func (v *View) ScrolledLinePos() (pos int)
- func (v *View) SetFace(face font.Face) error
- func (v *View) SetSize(size image.Point)
- func (v *View) StoredLineCount() (nline int)
- func (v *View) UnhighlightCommand() bool
Constants ¶
const ( AlignmentLeft = Alignment(attr.AlignmentLeft) AlignmentCenter = Alignment(attr.AlignmentCenter) AlignmentRight = Alignment(attr.AlignmentRight) )
const DefaultMaxRuneWidth = 80
default size of max of rune width in Frame.
Variables ¶
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{} )
var DefaultCachedImageSize = egimg.DefaultCacheSize
DefaultCachedImageSize is a default value for a cached image size.
Functions ¶
func DrawingString ¶
return string cotent that will be shown by Draw().
func StringFrom ¶
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.
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 Editor ¶
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 ¶
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) DeleteLastParagraphs ¶
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 ¶
get current Alignment of Paragraph.
func (*Editor) NewLineCount ¶
It returns count for outputting new line. return 0 at initial state.
func (*Editor) SetAlignment ¶
set Alignment to the editor so that writing text is aligned.
func (*Editor) WriteButton ¶
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
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 ¶
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 ¶
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
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) FirstParagraph ¶
returns the first paragraph of this frame.
func (*Frame) LineCount ¶
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 ¶
ParagraphCount returns the number of Paragraphs in this Frame.
This count excludes any soft returns inserted to wrap text to the maxWidth.
func (*Frame) SetMaxRuneWidth ¶
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.
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 ¶
return first Box. if not found return nil, indicating the line has no contents.
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 ¶
FirstLine returns the first Line of this Paragraph.
f is the Frame that contains the Paragraph.
func (*Paragraph) LineCount ¶
LineCount returns the number of Lines in this Paragraph.
This count includes any soft returns inserted to wrap text to the maxWidth.
type SpaceBox ¶ added in v0.9.0
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
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) FindCommand ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
scroll n lines. positive n corresponds to scroll up, otherwise down.
func (*View) ScrolledLinePos ¶ added in v0.7.0
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 ¶
Set font face which must be monospace. if font is not monospace return error. It changes Frame layout.
func (*View) StoredLineCount ¶ added in v0.7.0
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 ¶
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. |