Alignment specifies how text is aligned within the field.
type Alignment int
const ( // AlignStart aligns text at the start of the field. AlignStart Alignment = 0 // AlignCenter aligns text at the center of the field. AlignCenter Alignment = 1 // AlignEnd aligns text at the end of the field. AlignEnd Alignment = 2 )
InputField is a text input field. Call Update and Draw when your Game's Update and Draw methods are called.
Note: A position and size must be set via SetRect before the field will appear. Keyboard events are not handled by default, and may be enabled via SetHandleKeyboard.
type InputField struct { *TextField sync.Mutex // contains filtered or unexported fields }
func NewInputField(face font.Face, faceMutex *sync.Mutex) *InputField
NewInputField returns a new InputField. See type documentation for more info.
func (f *InputField) HandleKeyboardEvent(key ebiten.Key, r rune) (handled bool, err error)
HandleKeyboardEvent passes the provided key or rune to the Inputfield.
func (f *InputField) SetChangedFunc(changedFunc func(r rune) (accept bool))
SetChangedFunc sets a handler which is called when the text buffer is changed. The handler may return true to add the rune to the text buffer.
func (f *InputField) SetHandleKeyboard(handle bool)
SetHandleKeyboard sets a flag controlling whether keyboard input should be handled by the field. This can be used to facilitate focus changes between multiple inputs.
func (f *InputField) SetSelectedFunc(selectedFunc func() (accept bool))
SetSelectedFunc sets a handler which is called when the enter key is pressed. Providing a nil function value will remove the existing handler (if set). The handler may return true to clear the text buffer.
func (f *InputField) Update() error
Update updates the input field. This function should be called when Game.Update is called.
TextField is a text display field. Call Update and Draw when your Game's Update and Draw methods are called.
Note: A position and size must be set via SetRect before the field will appear. Keyboard events are not handled by default, and may be enabled via SetHandleKeyboard.
type TextField struct { sync.Mutex // contains filtered or unexported fields }
func NewTextField(face font.Face, faceMutex *sync.Mutex) *TextField
NewTextField returns a new TextField. See type documentation for more info.
func (f *TextField) Draw(screen *ebiten.Image)
Draw draws the field on the screen. This function should be called when Game.Draw is called.
func (f *TextField) ForegroundColor() color.RGBA
ForegroundColor returns the color of the text within the field.
func (f *TextField) HandleKeyboardEvent(key ebiten.Key, r rune) (handled bool, err error)
HandleKeyboardEvent passes the provided key or rune to the TextField.
func (f *TextField) HandleMouseEvent(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)
func (f *TextField) LineHeight() int
LineHeight returns the line height for the field.
func (f *TextField) Padding() int
Padding returns the amount of padding around the text within the field.
func (f *TextField) Rect() image.Rectangle
Rect returns the position and size of the field.
func (f *TextField) SetAutoHideScrollBar(autoHide bool)
SetAutoHideScrollBar sets whether the scroll bar is automatically hidden when the entire text buffer is visible.
func (f *TextField) SetBackgroundColor(c color.RGBA)
SetBackgroundColor sets the color of the background of the field.
func (f *TextField) SetFollow(follow bool)
SetFollow sets whether the field should automatically scroll to the end when content is added to the buffer.
func (f *TextField) SetFont(face font.Face, mutex *sync.Mutex)
SetFont sets the font face of the text within the field.
func (f *TextField) SetForegroundColor(c color.RGBA)
SetForegroundColor sets the color of the text within the field.
func (f *TextField) SetHandleKeyboard(handle bool)
SetHandleKeyboard sets a flag controlling whether keyboard input should be handled by the field. This can be used to facilitate focus changes between multiple inputs.
func (f *TextField) SetHorizontal(h Alignment)
SetHorizontal sets the horizontal alignment of the text within the field.
func (f *TextField) SetLast(text string)
SetLast sets the text of the last line of the field. Newline characters are replaced with spaces.
func (f *TextField) SetLineHeight(height int)
SetLineHeight sets a custom line height for the field. Setting a line height of 0 restores the automatic line height detection based on the font.
func (f *TextField) SetMask(r rune)
SetMask sets the rune used to mask the text buffer contents. Set to 0 to disable.
func (f *TextField) SetPadding(padding int)
SetPadding sets the amount of padding around the text within the field.
func (f *TextField) SetPrefix(text string)
SetPrefix sets the text shown before the content of the field.
func (f *TextField) SetRect(r image.Rectangle)
SetRect sets the position and size of the field.
func (f *TextField) SetScrollBarColors(area color.RGBA, handle color.RGBA)
SetScrollBarColors sets the color of the scroll bar area and handle.
func (f *TextField) SetScrollBarVisible(scrollVisible bool)
SetScrollBarVisible sets whether the scroll bar is visible on the screen.
func (f *TextField) SetScrollBarWidth(width int)
SetScrollBarWidth sets the width of the scroll bar.
func (f *TextField) SetScrollBorderColors(top color.RGBA, right color.RGBA, bottom color.RGBA, left color.RGBA)
SetScrollBorderColor sets the color of the top, right, bottom and left border of the scroll bar handle.
func (f *TextField) SetScrollBorderSize(size int)
SetScrollBorderSize sets the size of the border around the scroll bar handle.
func (f *TextField) SetSingleLine(single bool)
SetSingleLine sets whether the field displays all text on a single line. When enabled, the field scrolls horizontally. Otherwise, it scrolls vertically.
func (f *TextField) SetSuffix(text string)
SetSuffix sets the text shown after the content of the field.
func (f *TextField) SetText(text string)
SetText sets the text in the field.
func (f *TextField) SetVertical(v Alignment)
SetVertical sets the veritcal alignment of the text within the field.
func (f *TextField) SetVisible(visible bool)
SetVisible sets whether the field is visible on the screen.
func (f *TextField) SetWordWrap(wrap bool)
SetWordWrap sets a flag which, when enabled, causes text to wrap without breaking words.
func (f *TextField) Text() string
Text returns the text in the field.
func (f *TextField) Update() error
Update updates the field. This function should be called when Game.Update is called.
func (f *TextField) Visible() bool
Visible returns whether the field is currently visible on the screen.
func (f *TextField) WordWrap() bool
WordWrap returns the current text wrap mode.
func (f *TextField) Write(p []byte) (n int, err error)
Write writes to the field's buffer.