Documentation ¶
Index ¶
- Constants
- type Content
- type Editor
- func (e *Editor) Content() Content
- func (e *Editor) ContentName() string
- func (e *Editor) Cursor() (row int, col int)
- func (e *Editor) Draw(screen *ebiten.Image)
- func (e *Editor) Image() (img *ebiten.Image)
- func (e *Editor) IsModified() bool
- func (e *Editor) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)
- func (e *Editor) Load()
- func (e *Editor) MoveCursor(row int, col int)
- func (e *Editor) ReadText() []byte
- func (e *Editor) Save()
- func (e *Editor) SetContent(content Content)
- func (e *Editor) SetContentName(content_name string)
- func (e *Editor) Size() (width, height int)
- func (e *Editor) Update() error
- func (e *Editor) WriteText(text []byte)
- type EditorOption
- func WithBackgroundColor(opt color.Color) EditorOption
- func WithBackgroundImage(opt *ebiten.Image) EditorOption
- func WithBottomBar(enabled bool) EditorOption
- func WithClipboard(opt Content) EditorOption
- func WithColumns(opt int) EditorOption
- func WithContent(opt Content) EditorOption
- func WithContentName(opt string) EditorOption
- func WithCursorColor(opt color.Color) EditorOption
- func WithFontColor(opt color.Color) EditorOption
- func WithFontFace(opt font.Face) EditorOption
- func WithHeight(opt int) EditorOption
- func WithHighlightColor(opt color.Color) EditorOption
- func WithQuit(opt func()) EditorOption
- func WithRows(opt int) EditorOption
- func WithSearchColor(opt color.Color) EditorOption
- func WithTopBar(enabled bool) EditorOption
- func WithWidth(opt int) EditorOption
- func WithWithPadding(opt int) EditorOption
Constants ¶
const ( EDITOR_DEFAULT_ROWS = 25 EDITOR_DEFAULT_COLS = 80 )
const ( EDIT_MODE = iota SEARCH_MODE )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content interface { ReadText() []byte // Read the entire content of the text clipboard. WriteText([]byte) // Write replaces the entire content of the text clipboard. }
Content is an interface to a clipboard or file to read/write data. We use this instead of io.ReadWriter as we do not want to handle errors or buffered reads in the Editor; we force that to the caller of the editor.
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor is a simple text editor, compliant to the ebiten.Game interface.
The Meta or Control key can be used with the following command keys:
| Keystroke | Action | | --- | --- | | COMMAND-S | Save the content. | | COMMAND-L | Load the content. | | COMMAND-C | Copy the selection to clipboard. | | COMMAND-V | Paste clipboard into the selection/current cursor. | | COMMAND-X | Cut the selection, saving a copy into the clipboard. | | COMMAND-F | Find text in the content. | | COMMAND-Q | Quit the editor. |
func NewEditor ¶
func NewEditor(options ...EditorOption) (e *Editor)
NewEditor creates a new editor. See the EditorOption type for available options that can be passed to change its defaults.
If neither the WithHeight nor WithRows options are set, the editor defaults to 25 rows. The resulting image width is `rows * font.Face.Metrics().Height`
If neither the WithWidth nor the WithCols options are set, the editor defaults to 80 columns. The resulting image width is `cols * font.Face.GlyphAdvance('0')`
func (*Editor) ContentName ¶
ContentName() returns the current content name.
func (*Editor) Draw ¶
func (e *Editor) Draw(screen *ebiten.Image)
Draw the editor onto the screen, scaled to full size.
func (*Editor) Image ¶
func (e *Editor) Image() (img *ebiten.Image)
Return the internal image of the editor.
func (*Editor) IsModified ¶
IsModified returns true if the editor is in modified state.
func (*Editor) Load ¶
func (e *Editor) Load()
Load loads the text from the Content assigned to the editor.
func (*Editor) MoveCursor ¶
MoveCursor moves the cursor to the specified location. If `row` is `-1` then the cursor will be on the final row. If `col` is `-1` then the cursor is moved to the final rune in the row.
func (*Editor) ReadText ¶
ReadText returns all of the text in the editor. Note that this does not clear the 'modified' state of the editor.
func (*Editor) Save ¶
func (e *Editor) Save()
Save saves the text to the Content assigned to the editor. This clears the 'modified' bit also.
func (*Editor) SetContent ¶
SetContent() sets the content manager. NOTE: This does _not_ modify the editor until a Load()
func (*Editor) SetContentName ¶
SetContentName updates the top bar's content name.
type EditorOption ¶
type EditorOption func(e *Editor)
EditorOption is an option that can be sent to NewEditor()
func WithBackgroundColor ¶
func WithBackgroundColor(opt color.Color) EditorOption
WithBackgroundColor sets the color of the background.
func WithBackgroundImage ¶
func WithBackgroundImage(opt *ebiten.Image) EditorOption
WithBackgroundImage sets the ebiten.Image in the background. It will be scaled to fit the entire background of the editor.
func WithBottomBar ¶
func WithBottomBar(enabled bool) EditorOption
WithBottomBar enables the display of the last row as a help display.
func WithClipboard ¶
func WithClipboard(opt Content) EditorOption
WithClipboard sets the clipboard accessor. If set to nil, an in-memory content manager is used.
func WithColumns ¶
func WithColumns(opt int) EditorOption
WithColumns sets the total number of columns in the editor, including the line-number area, if enabled. If set to < 0, then:
- if WithWidth is set, then the maximum number of columns that would fit, based on font advance of the glyph '0', is used.
- if WithWidth is not set, then the number of columns defaults to 80.
func WithContent ¶
func WithContent(opt Content) EditorOption
WithContent sets the content accessor, and permits saving and loading. If set to nil, an in-memory content manager is used.
func WithContentName ¶
func WithContentName(opt string) EditorOption
WithContentName sets the name of the content
func WithCursorColor ¶
func WithCursorColor(opt color.Color) EditorOption
WithCursorColor sets the color of the cursor over the text. It is recommended to have an Alpha component of 90.
func WithFontColor ¶
func WithFontColor(opt color.Color) EditorOption
WithFontColor sets the color of the text. It is recommended to have an Alpha component of 255.
func WithFontFace ¶
func WithFontFace(opt font.Face) EditorOption
WithFontFace set the default font. If set to nil, the monospace font `github.com/hajimehoshi/bitmapfont/v3` is used.
func WithHeight ¶
func WithHeight(opt int) EditorOption
WidthHeight sets the image height of the editor. If WithRows is set, the font is scaled appropriately to the height. If WithRows is not set, the maximum number of rows that would fit are used, with any additional padding to the bottom of the editor. If not set, see the 'WithRows()' option for the calculation.
func WithHighlightColor ¶
func WithHighlightColor(opt color.Color) EditorOption
WithHighlightColor sets the color of the select highlight over the text. It is recommended to have an Alpha component of 70.
func WithQuit ¶
func WithQuit(opt func()) EditorOption
WithQuit sets the function to call when ^Q is pressed, nominally to quit the editor. The default is no action.
func WithRows ¶
func WithRows(opt int) EditorOption
WithRows sets the total number of rows in the editor, including the top bar and bottom bar, if enabled. If set to < 0, then:
- if WithHeight is set, then the maximum number of rows that would fit, based on font height, is used.
- if WithHeight is not set, then the number of rows defaults to 25.
func WithSearchColor ¶
func WithSearchColor(opt color.Color) EditorOption
WithSearchColor sets the color of the search highlight over the text. It is recommended to have an Alpha component of 70.
func WithTopBar ¶
func WithTopBar(enabled bool) EditorOption
WithTopBar enables the display of the first row as a top bar.
func WithWidth ¶
func WithWidth(opt int) EditorOption
WidthWidth sets the image width of the editor. If WithColumns is set, the font is scaled appropriately to the width. If WithColumns is not set, the maximum number of columns that would fit are used, with any additional padding to the bottom of the editor. If not set, see the 'WithColumns()' option for the calculation.
func WithWithPadding ¶
func WithWithPadding(opt int) EditorOption
WithWidthPadding sets the left and right side padding, in pixels. If not set, the default is 1/2 of the width of the text advance of the font's rune '0'.