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 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) WriteLabel(text string) (n int, err error)
- func (e *Editor) WriteLine(sym string) (n 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 Line
- type Paragraph
- type TextBox
- type View
- func (v *View) Draw(m *image.RGBA, origin image.Point)
- func (v *View) FindCommand(p image.Point) (string, bool)
- func (v *View) HighlightCommand(p image.Point) bool
- func (v *View) LineCount() int
- func (v *View) RuneWidth() int
- func (v *View) Scroll(moveY int)
- func (v *View) ScrollLine(n int)
- func (v *View) SetFace(face font.Face) error
- func (v *View) SetSize(size image.Point)
- 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{} )
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. // 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) 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.
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 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 TextBox ¶
type TextBox interface { Text(*Frame) string Bytes(*Frame) []byte // contains filtered or unexported methods }
TextBox holds text and can show it for user.
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) 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) 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) SetFace ¶
Set font face which must be monospace. if font is not monospace return error. It changes Frame layout.
func (*View) UnhighlightCommand ¶
Unhighlight all the command in View. return highlighted button exist and is Unhighlighted.