etk

package module
v0.0.0-...-500cae8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 19 Imported by: 1

README

etk - Ebitengine Tool Kit

GoDoc Donate via LiberaPay

Ebitengine tool kit for creating graphical user interfaces

Note: This library is still in development. Breaking changes may be made until v1.0 is released.

Features

  • Simplifies GUI development:
    • Propagates layout changes.
    • Propagates user input.
    • Propagates focus.
  • Extensible by design:
    • The Box widget is provided as a building block for custom widgets.
    • Widgets may be nested within each other efficiently.
  • Tools in the kit:
    • Box: Building block for creating custom widgets.
    • Button: Clickable button.
    • Flex: Flexible stack-based layout. Each Flex widget may be oriented horizontally or vertically.
    • Frame: Widget container. All child widgets are displayed at once. Child widgets are not repositioned by default.
    • Grid: Highly customizable cell-based layout. Each widget added to the Grid may span multiple cells.
    • Input: Text input widget. The Input widget is simply a Text widget that also accepts user input.
    • List: List of widgets as selectable items.
    • Text: Text display widget.
    • Window: Widget paging mechanism. Only one widget added to a window is displayed at a time.

Demo

Boxcars uses etk extensively and is available at https://play.bgammon.org

Screenshot

Examples

See the examples folder.

Documentation

Documentation is available via godoc.

Support

Please share issues and suggestions here.

Documentation

Overview

Package etk provides an Ebitengine tool kit for creating graphical user interfaces.

Widgets

Custom widgets may be created entirely from scratch or may be based on official widgets.

The following official widgets are available:

Box - Building block for creating other widgets.
Button - Clickable button.
Flex - Flexible stack-based layout. Each Flex widget may be oriented horizontally or vertically.
Frame - Widget container. All child widgets are displayed at once. Child widgets are not repositioned by default.
Grid - Highly customizable cell-based layout. Widgets added to the Grid may span multiple cells.
Input - Text input widget. The Input widget is simply a Text widget that also accepts user input.
List - List of widgets as selectable items.
Text - Text display widget.
Window - Widget paging mechanism. Only one widget added to a window is displayed at a time.

Input Propagation

Mouse events are passed to the topmost widget under the mouse. If a widget returns a handled value of false, the event continues to propagate down the stack of widgets under the mouse.

Clicking or tapping on a widget focuses the widget. This is handled by etk automatically when a widget returns a handled value of true.

Keyboard events are passed to the focused widget.

Focus Propagation

When attempting to change which widget is focused, etk checks whether the widget to be focused accepts this focus. If it does, the previously focused widget is un-focused. If the widget does not accept the focus, the previously focused widget remains focused.

Cursor Unification

Input events generated by desktop mice and touch screens are unified in etk. These input events are simplified into an image.Point specifying the location of the event and two parameters: clicked and pressed.

Clicked is true the first frame the mouse event or touch screen event is received. When the mouse click or touch screen tap is released, the widget that was originally clicked or tapped always receives a final event where clicked and pressed are both false.

Draw Order

Each time etk draws a widget it subsequently draws all of the widget's children in the order they are returned.

Subpackages

There are two subpackages in etk: messeji and kibodo. These are available for use without requiring etk. Usually you will not need to reference any subpackages, as etk wraps them to provide widgets with additional features.

Index

Constants

This section is empty.

Variables

View Source
var Bindings = &Shortcuts{
	ConfirmKeyboard: []ebiten.Key{ebiten.KeyEnter, ebiten.KeyKPEnter},
	ConfirmMouse:    []ebiten.MouseButton{ebiten.MouseButtonLeft, ebiten.MouseButtonRight},
	ConfirmGamepad:  []ebiten.GamepadButton{ebiten.GamepadButton0},
}

Bindings is the current keyboard shortcut configuration.

View Source
var Style = &Attributes{
	TextFont: defaultFont(),
	TextSize: 32,

	TextColorLight: color.RGBA{255, 255, 255, 255},
	TextColorDark:  color.RGBA{0, 0, 0, 255},

	TextBgColor: transparent,

	BorderSize: 4,

	BorderColorTop:    color.RGBA{220, 220, 220, 255},
	BorderColorRight:  color.RGBA{0, 0, 0, 255},
	BorderColorBottom: color.RGBA{0, 0, 0, 255},
	BorderColorLeft:   color.RGBA{220, 220, 220, 255},

	ScrollAreaColor:   color.RGBA{200, 200, 200, 255},
	ScrollHandleColor: color.RGBA{108, 108, 108, 255},

	ScrollBorderSize: 2,

	ScrollBorderColorTop:    color.RGBA{240, 240, 240, 255},
	ScrollBorderColorRight:  color.RGBA{0, 0, 0, 255},
	ScrollBorderColorBottom: color.RGBA{0, 0, 0, 255},
	ScrollBorderColorLeft:   color.RGBA{240, 240, 240, 255},

	InputBgColor: color.RGBA{0, 128, 0, 255},

	ButtonBgColor:         color.RGBA{255, 255, 255, 255},
	ButtonBgColorDisabled: color.RGBA{110, 110, 110, 255},
}

Style is the current default attribute configuration. Integer values will be scaled.

Functions

func BoundString

func BoundString(f font.Face, s string) image.Rectangle

BoundString returns the bounds of the provided string.

func Draw

func Draw(screen *ebiten.Image) error

Draw draws the root widget and its children to the screen.

func FontFace

func FontFace(fnt *sfnt.Font, size int) font.Face

FontFace returns a face for the provided font and size. Scaling is not applied.

func Layout

func Layout(outsideWidth int, outsideHeight int)

Layout sets the current screen size and resizes the root widget.

func Scale

func Scale(v int) int

Scale applies the device scale factor to the provided value and returns the result. When running on Android, this function may only be called during or after the first Layout call made by Ebitengine.

func ScaleFactor

func ScaleFactor() float64

ScaleFactor returns the device scale factor. When running on Android, this function may only be called during or after the first Layout call made by Ebitengine.

func ScreenSize

func ScreenSize() (width int, height int)

ScreenSize returns the current screen size.

func SetDebug

func SetDebug(debug bool)

SetDebug sets whether debug information is drawn on screen. When enabled, all visible widgets are outlined.

func SetFocus

func SetFocus(w Widget)

SetFocus focuses a widget.

func SetRoot

func SetRoot(w Widget)

SetRoot sets the root widget. The root widget and all of its children will be drawn on the screen and receive user input. The root widget will also be focused. To temporarily disable etk, set a nil root widget.

func Update

func Update() error

Update handles user input and passes it to the focused or clicked widget.

Types

type Alignment

type Alignment int

Alignment specifies how text is aligned within the field.

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
)

type Attributes

type Attributes struct {
	TextFont *sfnt.Font
	TextSize int

	TextColorLight color.RGBA
	TextColorDark  color.RGBA

	TextBgColor color.RGBA

	BorderSize int

	BorderColorTop    color.RGBA
	BorderColorRight  color.RGBA
	BorderColorBottom color.RGBA
	BorderColorLeft   color.RGBA

	ScrollAreaColor   color.RGBA
	ScrollHandleColor color.RGBA

	ScrollBorderSize int

	ScrollBorderColorTop    color.RGBA
	ScrollBorderColorRight  color.RGBA
	ScrollBorderColorBottom color.RGBA
	ScrollBorderColorLeft   color.RGBA

	InputBgColor color.RGBA

	ButtonTextColor       color.RGBA
	ButtonBgColor         color.RGBA
	ButtonBgColorDisabled color.RGBA
}

Attributes represents a default attribute configuration. Integer values will be scaled.

type Box

type Box struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Box is a building block for other widgets. It may also be used as a spacer in layout widgets.

func NewBox

func NewBox() *Box

NewBox returns a new Box widget.

func (*Box) AddChild

func (b *Box) AddChild(w ...Widget)

AddChild adds a child to the widget.

func (*Box) Background

func (b *Box) Background() color.RGBA

Background returns the background color of the widget.

func (*Box) Children

func (b *Box) Children() []Widget

Children returns the children of the widget. Children are drawn in the order they are returned. Keyboard and mouse events are passed to children in reverse order.

func (*Box) Clear

func (b *Box) Clear()

Clear removes all children from the widget.

func (*Box) Draw

func (b *Box) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Box) Focus

func (b *Box) Focus() bool

Focus returns the focus state of the widget.

func (*Box) HandleKeyboard

func (b *Box) HandleKeyboard(key ebiten.Key, r rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Box) HandleMouse

func (b *Box) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs. Only mouse events that are on top of the widget are passed to the widget.

func (*Box) Rect

func (b *Box) Rect() image.Rectangle

Rect returns the position and size of the widget.

func (*Box) SetBackground

func (b *Box) SetBackground(background color.RGBA)

SetBackground sets the background color of the widget.

func (*Box) SetFocus

func (b *Box) SetFocus(focus bool) bool

SetFocus sets the focus state of the widget.

func (*Box) SetRect

func (b *Box) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Box) SetVisible

func (b *Box) SetVisible(visible bool)

SetVisible sets the visibility of the widget.

func (*Box) Visible

func (b *Box) Visible() bool

Visible returns the visibility of the widget.

type Button

type Button struct {
	*Box
	// contains filtered or unexported fields
}

Button is a clickable button.

func NewButton

func NewButton(label string, onSelected func() error) *Button

NewButton returns a new Button widget.

func (*Button) Draw

func (b *Button) Draw(screen *ebiten.Image) error

Draw draws the button on the screen.

func (*Button) HandleKeyboard

func (b *Button) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Button) HandleMouse

func (b *Button) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Button) SetBorderColors

func (b *Button) SetBorderColors(top color.RGBA, right color.RGBA, bottom color.RGBA, left color.RGBA)

SetBorderColors sets the color of the top, right, bottom and left border.

func (*Button) SetBorderSize

func (b *Button) SetBorderSize(size int)

SetBorderSize sets the size of the border around the button.

func (*Button) SetFont

func (b *Button) SetFont(fnt *sfnt.Font, size int)

SetFont sets the font and text size of button label. Scaling is not applied.

func (*Button) SetRect

func (b *Button) SetRect(r image.Rectangle)

SetRect sets the position and size of the Button.

func (*Button) SetText

func (b *Button) SetText(text string)

SetText sets the text in the field.

func (*Button) Text

func (b *Button) Text() string

Text returns the content of the text buffer.

type Checkbox

type Checkbox struct {
	*Box
	// contains filtered or unexported fields
}

Checkbox is a toggleable Checkbox.

func NewCheckbox

func NewCheckbox(onSelect func() error) *Checkbox

NewCheckbox returns a new Checkbox widget.

func (*Checkbox) Draw

func (c *Checkbox) Draw(screen *ebiten.Image) error

Draw draws the Checkbox on the screen.

func (*Checkbox) HandleKeyboard

func (c *Checkbox) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Checkbox) HandleMouse

func (c *Checkbox) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Checkbox) Selected

func (c *Checkbox) Selected() bool

Selected returns the selection state of the Checkbox.

func (*Checkbox) SetBorderColor

func (c *Checkbox) SetBorderColor(borderColor color.RGBA)

SetBorderColor sets the border color of the Checkbox.

func (*Checkbox) SetCheckColor

func (c *Checkbox) SetCheckColor(checkColor color.RGBA)

SetCheckColor sets the check mark color of the Checkbox.

func (*Checkbox) SetRect

func (c *Checkbox) SetRect(r image.Rectangle)

SetRect sets the position and size of the Checkbox. The checkbox is always a square shape.

func (*Checkbox) SetSelected

func (c *Checkbox) SetSelected(selected bool)

SetSelected sets the Checkbox selection state. The onSelect function is not called when the value is set manually via SetSelected.

type Flex

type Flex struct {
	*Box
	// contains filtered or unexported fields
}

Flex is a flexible stack-based layout which may be oriented horizontally or vertically. Children are positioned with equal spacing by default. A minimum size may instead be specified via SetChildSize, causing children to be positioned similar to a flexbox, where each child either has the minimum size or the child stretches to fill the remaining row or column.

func NewFlex

func NewFlex() *Flex

NewFlex returns a new Flex widget.

func (*Flex) AddChild

func (f *Flex) AddChild(w ...Widget)

AddChild adds a child to the widget.

func (*Flex) Draw

func (f *Flex) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Flex) HandleKeyboard

func (f *Flex) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Flex) HandleMouse

func (f *Flex) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Flex) SetChildSize

func (f *Flex) SetChildSize(width int, height int)

SetChildSize sets the minimum size of each child in the Flex.

func (*Flex) SetGaps

func (f *Flex) SetGaps(columnGap int, rowGap int)

SetGaps sets the gaps between each child in the Flex.

func (*Flex) SetRect

func (f *Flex) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Flex) SetVertical

func (f *Flex) SetVertical(v bool)

SetVertical sets the orientation of the child widget stacking.

type Frame

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

Frame is a widget container. All children are displayed at once. Children are not repositioned by default. Repositioning may be enabled via SetPositionChildren.

func NewFrame

func NewFrame(w ...Widget) *Frame

NewFrame returns a new Frame widget.

func (*Frame) AddChild

func (f *Frame) AddChild(w ...Widget)

AddChild adds a child to the widget.

func (*Frame) SetPadding

func (f *Frame) SetPadding(padding int)

SetPadding sets the amount of padding around widgets in the frame.

func (*Frame) SetPositionChildren

func (f *Frame) SetPositionChildren(position bool)

SetPositionChildren sets a flag that determines whether child widgets are repositioned when the Frame is repositioned.

func (*Frame) SetRect

func (f *Frame) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

type Grid

type Grid struct {
	*Box
	// contains filtered or unexported fields
}

Grid is a highly customizable cell-based layout. Widgets added to the Grid may span multiple cells.

func NewGrid

func NewGrid() *Grid

NewGrid returns a new Grid widget.

func (*Grid) AddChild

func (g *Grid) AddChild(wgt ...Widget)

AddChild adds a widget to the Grid at 0,0. To add widgets to a Grid, you should use AddChildAt instead.

func (*Grid) AddChildAt

func (g *Grid) AddChildAt(wgt Widget, x int, y int, columns int, rows int)

AddChildAt adds a widget to the Grid at the specified position. Each widget added to the grid may span multiple cells.

func (*Grid) Clear

func (g *Grid) Clear()

Clear removes all children from the Grid.

func (*Grid) Draw

func (g *Grid) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Grid) HandleKeyboard

func (g *Grid) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Grid) HandleMouse

func (g *Grid) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Grid) SetColumnPadding

func (g *Grid) SetColumnPadding(padding int)

SetColumnPadding sets the amount of padding between each column.

func (*Grid) SetColumnSizes

func (g *Grid) SetColumnSizes(size ...int)

SetColumnSizes sets the size of each column. A size of -1 represents an equal proportion of the available space.

func (*Grid) SetRect

func (g *Grid) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Grid) SetRowPadding

func (g *Grid) SetRowPadding(padding int)

SetRowPadding sets the amount of padding between each row.

func (*Grid) SetRowSizes

func (g *Grid) SetRowSizes(size ...int)

SetRowSizes sets the size of each row. A size of -1 represents an equal proportion of the available space.

type Input

type Input struct {
	*Box
	// contains filtered or unexported fields
}

Input is a text input widget. The Input widget is simply a Text widget that also accepts user input.

func NewInput

func NewInput(text string, onSelected func(text string) (handled bool)) *Input

NewInput returns a new Input widget.

func (*Input) Draw

func (i *Input) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Input) Focus

func (i *Input) Focus() bool

Focus returns the focus state of the widget.

func (*Input) Foreground

func (i *Input) Foreground() color.RGBA

Foreground return the color of the text within the field.

func (*Input) HandleKeyboard

func (i *Input) HandleKeyboard(key ebiten.Key, r rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Input) HandleMouse

func (i *Input) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Input) Padding

func (i *Input) Padding() int

Padding returns the amount of padding around the text within the field.

func (*Input) SetAutoHideScrollBar

func (i *Input) SetAutoHideScrollBar(autoHide bool)

SetAutoHideScrollBar sets whether the scroll bar is automatically hidden when the entire text buffer is visible.

func (*Input) SetCursor

func (i *Input) SetCursor(cursor string)

SetCursor sets the cursor appended to the text buffer when focused.

func (*Input) SetFocus

func (i *Input) SetFocus(focus bool) bool

SetFocus sets the focus state of the widget.

func (*Input) SetFont

func (t *Input) SetFont(fnt *sfnt.Font, size int)

SetFont sets the font and text size of the field. Scaling is not applied.

func (*Input) SetForeground

func (i *Input) SetForeground(c color.RGBA)

SetForegroundColor sets the color of the text within the field.

func (*Input) SetHorizontal

func (i *Input) SetHorizontal(h Alignment)

SetHorizontal sets the horizontal alignment of the text within the field.

func (*Input) SetMask

func (i *Input) SetMask(r rune)

SetMask sets the rune used to mask the text buffer contents. Set to 0 to disable.

func (*Input) SetPadding

func (i *Input) SetPadding(padding int)

SetPadding sets the amount of padding around the text within the field.

func (*Input) SetPrefix

func (i *Input) SetPrefix(prefix string)

SetPrefix sets the text shown before the input text.

func (*Input) SetRect

func (i *Input) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Input) SetScrollBarColors

func (i *Input) SetScrollBarColors(area color.RGBA, handle color.RGBA)

SetScrollBarColors sets the color of the scroll bar area and handle.

func (*Input) SetScrollBarVisible

func (i *Input) SetScrollBarVisible(scrollVisible bool)

SetScrollBarVisible sets whether the scroll bar is visible on the screen.

func (*Input) SetScrollBarWidth

func (i *Input) SetScrollBarWidth(width int)

SetScrollBarWidth sets the width of the scroll bar.

func (*Input) SetSuffix

func (i *Input) SetSuffix(suffix string)

SetSuffix sets the text shown after the input text.

func (*Input) SetText

func (i *Input) SetText(text string)

SetText sets the text in the field.

func (*Input) SetVertical

func (i *Input) SetVertical(h Alignment)

SetVertical sets the vertical alignment of the text within the field.

func (*Input) SetWordWrap

func (i *Input) SetWordWrap(wrap bool)

SetWordWrap sets a flag which, when enabled, causes text to wrap without breaking words.

func (*Input) Text

func (i *Input) Text() string

Text returns the content of the text buffer.

func (*Input) Write

func (i *Input) Write(p []byte) (n int, err error)

Write writes to the text buffer.

type Keyboard

type Keyboard struct {
	*Box
	// contains filtered or unexported fields
}

Keyboard is an on-screen keyboard widget. User input is automatically passed to the focused widget.

func NewKeyboard

func NewKeyboard() *Keyboard

NewKeyboard returns a new Keyboard widget.

func (*Keyboard) Draw

func (k *Keyboard) Draw(screen *ebiten.Image) error

Draw draws the keyboard on the screen.

func (*Keyboard) GetKeys

func (k *Keyboard) GetKeys() [][]*kibodo.Key

GetKeys returns the keys of the keyboard.

func (*Keyboard) HandleMouse

func (k *Keyboard) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Keyboard) SetExtendedKeys

func (k *Keyboard) SetExtendedKeys(keys [][]*kibodo.Key)

SetExtendedKeys sets the keys of the keyboard when the .

func (*Keyboard) SetKeys

func (k *Keyboard) SetKeys(keys [][]*kibodo.Key)

SetKeys sets the keys of the keyboard.

func (*Keyboard) SetRect

func (k *Keyboard) SetRect(r image.Rectangle)

SetRect sets the position and size of the keyboard.

func (*Keyboard) SetScheduleFrameFunc

func (k *Keyboard) SetScheduleFrameFunc(f func())

SetScheduleFrameFunc sets the function called whenever the screen should be redrawn.

func (*Keyboard) SetShowExtended

func (k *Keyboard) SetShowExtended(show bool)

SetShowExtended sets whether the normal or extended keyboard is shown.

type List

type List struct {
	sync.Mutex
	// contains filtered or unexported fields
}

List is a list of widgets. Rows or cells may optionally be selectable.

func NewList

func NewList(itemHeight int, onSelected func(index int) (accept bool)) *List

NewList returns a new List widget.

func (*List) AddChildAt

func (l *List) AddChildAt(w Widget, x int, y int)

AddChildAt adds a widget to the list at the specified position.

func (*List) Background

func (l *List) Background() color.RGBA

Background returns the background color of the widget.

func (*List) Children

func (l *List) Children() []Widget

Children returns the children of the widget. Children are drawn in the order they are returned. Keyboard and mouse events are passed to children in reverse order.

func (*List) Clear

func (l *List) Clear()

Clear clears all items from the list.

func (*List) Draw

func (l *List) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*List) Focus

func (l *List) Focus() bool

Focus returns the focus state of the widget.

func (*List) HandleKeyboard

func (l *List) HandleKeyboard(key ebiten.Key, r rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*List) HandleMouse

func (l *List) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs. Only mouse events that are on top of the widget are passed to the widget.

func (*List) Rect

func (l *List) Rect() image.Rectangle

Rect returns the position and size of the widget.

func (*List) Rows

func (l *List) Rows() int

Rows returns the number of rows in the list.

func (*List) SelectedItem

func (l *List) SelectedItem() (x int, y int)

SelectedItem returns the selected list item.

func (*List) SetBackground

func (l *List) SetBackground(background color.RGBA)

SetBackground sets the background color of the widget.

func (*List) SetColumnSizes

func (l *List) SetColumnSizes(size ...int)

SetColumnSizes sets the size of each column. A size of -1 represents an equal proportion of the available space.

func (*List) SetDrawBorder

func (l *List) SetDrawBorder(drawBorder bool)

SetDrawBorder enables or disables borders being drawn around the list.

func (*List) SetFocus

func (l *List) SetFocus(focus bool) (accept bool)

SetFocus sets the focus state of the widget.

func (*List) SetHighlightColor

func (l *List) SetHighlightColor(c color.RGBA)

SetHighlightColor sets the color used to highlight the currently selected item.

func (*List) SetItemHeight

func (l *List) SetItemHeight(itemHeight int)

SetItemHeight sets the height of the list items.

func (*List) SetRect

func (l *List) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*List) SetScrollBarColors

func (l *List) SetScrollBarColors(area color.RGBA, handle color.RGBA)

SetScrollBarColors sets the color of the scroll bar area and handle.

func (*List) SetScrollBarWidth

func (l *List) SetScrollBarWidth(width int)

SetScrollBarWidth sets the width of the scroll bar.

func (*List) SetSelectedFunc

func (l *List) SetSelectedFunc(f func(index int) (accept bool))

SetSelectedFunc sets a handler which is called when a list item is selected. Providing a nil function value will remove the existing handler (if set). The handler may return false to return the selection to its original state.

func (*List) SetSelectedItem

func (l *List) SetSelectedItem(x int, y int)

SetSelectedItem sets the selected list item.

func (*List) SetSelectionMode

func (l *List) SetSelectionMode(selectionMode SelectionMode)

SetSelectionMode sets the selection mode of the list.

func (*List) SetVisible

func (l *List) SetVisible(visible bool)

SetVisible sets the visibility of the widget.

func (*List) Visible

func (l *List) Visible() bool

Visible returns the visibility of the widget.

type Select

type Select struct {
	*Box
	// contains filtered or unexported fields
}

Select is a dropdown selection widget.

func NewSelect

func NewSelect(itemHeight int, onSelect func(index int) (accept bool)) *Select

NewSelect returns a new Select widget.

func (*Select) AddChild

func (s *Select) AddChild(w ...Widget)

AddChild adds a child to the widget. Selection options are added via AddOption.

func (*Select) AddOption

func (s *Select) AddOption(label string)

AddOption adds an option to the widget.

func (*Select) Children

func (s *Select) Children() []Widget

Children returns the children of the widget.

func (*Select) Clear

func (s *Select) Clear()

Clear removes all children from the widget.

func (*Select) Draw

func (s *Select) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Select) HandleKeyboard

func (s *Select) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Select) HandleMouse

func (s *Select) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Select) SetHighlightColor

func (s *Select) SetHighlightColor(c color.RGBA)

SetHighlightColor sets the color used to highlight the currently selected item.

func (*Select) SetMenuVisible

func (s *Select) SetMenuVisible(visible bool)

SetMenuVisible sets the visibility of the dropdown menu.

func (*Select) SetRect

func (s *Select) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Select) SetSelectedItem

func (s *Select) SetSelectedItem(index int)

SetSelectedItem sets the currently selected item.

type SelectionMode

type SelectionMode int

SelectionMode represents a mode of selection.

const (
	// SelectNone disables selection.
	SelectNone SelectionMode = iota

	// SelectRow enables selection by row.
	SelectRow

	// SelectColumn enables selection by column.
	SelectColumn
)

Selection modes.

type Shortcuts

type Shortcuts struct {
	ConfirmKeyboard []ebiten.Key
	ConfirmMouse    []ebiten.MouseButton
	ConfirmGamepad  []ebiten.GamepadButton

	// A sentinel rune value may be set for the confirm and back actions.
	// This allows working around on-screen keyboard issues on Android.
	ConfirmRune rune
	BackRune    rune
}

Shortcuts represents a keyboard shortcut configuration.

type Text

type Text struct {
	*Box
	// contains filtered or unexported fields
}

Text is a text display widget.

func NewText

func NewText(text string) *Text

NewText returns a new Text widget.

func (*Text) AddChild

func (t *Text) AddChild(w ...Widget)

AddChild adds a child to the widget.

func (*Text) Children

func (t *Text) Children() []Widget

Children returns the children of the widget.

func (*Text) Draw

func (t *Text) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Text) Focus

func (t *Text) Focus() bool

Focus returns the focus state of the widget.

func (*Text) Foreground

func (t *Text) Foreground() color.RGBA

Foreground return the color of the text within the field.

func (*Text) HandleKeyboard

func (t *Text) HandleKeyboard(key ebiten.Key, r rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Text) HandleMouse

func (t *Text) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Text) Padding

func (t *Text) Padding() int

Padding returns the amount of padding around the text within the field.

func (*Text) SetAutoHideScrollBar

func (t *Text) SetAutoHideScrollBar(autoHide bool)

SetAutoHideScrollBar sets whether the scroll bar is automatically hidden when the entire text buffer is visible.

func (*Text) SetFocus

func (t *Text) SetFocus(focus bool) bool

SetFocus sets the focus state of the widget.

func (*Text) SetFollow

func (t *Text) SetFollow(follow bool)

SetFollow sets whether the field should automatically scroll to the end when content is added to the buffer.

func (*Text) SetFont

func (t *Text) SetFont(fnt *sfnt.Font, size int)

SetFont sets the font and text size of the field. Scaling is not applied.

func (*Text) SetForeground

func (t *Text) SetForeground(c color.RGBA)

SetForegroundColor sets the color of the text within the field.

func (*Text) SetHorizontal

func (t *Text) SetHorizontal(h Alignment)

SetHorizontal sets the horizontal alignment of the text within the field.

func (*Text) SetMask

func (t *Text) SetMask(r rune)

SetMask sets the rune used to mask the text buffer contents. Set to 0 to disable.

func (*Text) SetPadding

func (t *Text) SetPadding(padding int)

SetPadding sets the amount of padding around the text within the field.

func (*Text) SetRect

func (t *Text) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Text) SetScrollBarColors

func (t *Text) SetScrollBarColors(area color.RGBA, handle color.RGBA)

SetScrollBarColors sets the color of the scroll bar area and handle.

func (*Text) SetScrollBarVisible

func (t *Text) SetScrollBarVisible(scrollVisible bool)

SetScrollBarVisible sets whether the scroll bar is visible on the screen.

func (*Text) SetScrollBarWidth

func (t *Text) SetScrollBarWidth(width int)

SetScrollBarWidth sets the width of the scroll bar.

func (*Text) SetScrollBorderColors

func (t *Text) 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 (*Text) SetSingleLine

func (t *Text) 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 (*Text) SetText

func (t *Text) SetText(text string)

SetText sets the text in the field.

func (*Text) SetVertical

func (t *Text) SetVertical(h Alignment)

SetVertical sets the vertical alignment of the text within the field.

func (*Text) SetWordWrap

func (t *Text) SetWordWrap(wrap bool)

SetWordWrap sets a flag which, when enabled, causes text to wrap without breaking words.

func (*Text) Text

func (t *Text) Text() string

Text returns the content of the text buffer.

func (*Text) Write

func (t *Text) Write(p []byte) (n int, err error)

Write writes to the text buffer.

type Widget

type Widget interface {
	// Rect returns the position and size of the widget.
	Rect() image.Rectangle

	// SetRect sets the position and size of the widget.
	SetRect(r image.Rectangle)

	// Background returns the background color of the widget.
	Background() color.RGBA

	// SetBackground sets the background color of the widget.
	SetBackground(background color.RGBA)

	// Focus returns the focus state of the widget.
	Focus() bool

	// SetFocus sets the focus state of the widget.
	SetFocus(focus bool) (accept bool)

	// Visible returns the visibility of the widget.
	Visible() bool

	// SetVisible sets the visibility of the widget.
	SetVisible(visible bool)

	// HandleKeyboard is called when a keyboard event occurs.
	HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

	// HandleMouse is called when a mouse event occurs. Only mouse events that
	// are on top of the widget are passed to the widget.
	HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

	// Draw draws the widget on the screen.
	Draw(screen *ebiten.Image) error

	// Children returns the children of the widget. Children are drawn in the
	// order they are returned. Keyboard and mouse events are passed to children
	// in reverse order.
	Children() []Widget
}

Widget represents an interface element. Most widgets will embed Box and build on top of it.

func At

func At(p image.Point) Widget

At returns the widget at the provided screen location.

func Focused

func Focused() Widget

Focused returns the currently focused widget. If no widget is focused, nil is returned.

type Window

type Window struct {
	*Box
	// contains filtered or unexported fields
}

Window displays child widgets in floating or maximized windows.

func NewWindow

func NewWindow() *Window

NewWindow returns a new Window widget.

func (*Window) AddChild

func (w *Window) AddChild(wgt ...Widget)

AddChild adds a child to the window.

func (*Window) AddChildWithTitle

func (w *Window) AddChildWithTitle(wgt Widget, title string) int

AddChildWithTitle adds a child to the window with the specified window title.

func (*Window) Children

func (w *Window) Children() []Widget

Children returns the children of the widget.

func (*Window) Clear

func (w *Window) Clear()

Clear removes all children from the widget.

func (*Window) Draw

func (w *Window) Draw(screen *ebiten.Image) error

Draw draws the widget on the screen.

func (*Window) HandleKeyboard

func (w *Window) HandleKeyboard(ebiten.Key, rune) (handled bool, err error)

HandleKeyboard is called when a keyboard event occurs.

func (*Window) HandleMouse

func (w *Window) HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)

HandleMouse is called when a mouse event occurs.

func (*Window) SetFont

func (w *Window) SetFont(fnt *sfnt.Font, size int)

SetFont sets the font and text size of the window titles. Scaling is not applied.

func (*Window) SetFrameSize

func (w *Window) SetFrameSize(size int)

SetFrameSize sets the size of the frame around each window.

func (*Window) SetFullscreen

func (w *Window) SetFullscreen(index int)

SetFullscreen expands the specified widget to fill the netire screen, hiding the title bar. When -1 is provided, the currently fullscreen widget is restored to its a normal size.

func (*Window) SetRect

func (w *Window) SetRect(r image.Rectangle)

SetRect sets the position and size of the widget.

func (*Window) SetTitleSize

func (w *Window) SetTitleSize(size int)

SetTitleSize sets the height of the title bars.

Directories

Path Synopsis
Package kibodo provides an on-screen keyboard widget for Ebitengine.
Package kibodo provides an on-screen keyboard widget for Ebitengine.
Package messeji provides text widgets for Ebitengine.
Package messeji provides text widgets for Ebitengine.

Jump to

Keyboard shortcuts

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