ebui

package module
v0.0.0-...-e43d3ec Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 9 Imported by: 0

README

Documentation

Overview

Package ebui provides an immediate mode GUI built on top of Ebitengine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CursorPosition

func CursorPosition() image.Point

func InitGame

func InitGame(g ebiten.Game) ebiten.Game

InitGame wraps an ebiten.Game and must be used for interactive widgets.

func Overlay

func Overlay(w Widget, viewport image.Rectangle)

Overlay a widget on top of the screen content.

Types

type Alignment

type Alignment uint8

Alignment along an axis.

const (
	Start Alignment = iota
	Middle
	End
)

func (Alignment) Align

func (a Alignment) Align(cont, dim int) int

Align returns the offset for a widget of size `dim` within a container of size `cont`.

It panics on an invalid Alignment.

type Applier

type Applier interface {
	Apply(Widget) Widget
}

type Apply

type Apply struct {
	Widget Applier
	WidgetList
}

Apply the Widget to all elements in the WidgetList.

func (Apply) At

func (a Apply) At(index int) Widget

type Axis

type Axis uint8

Axis is represents either the horizontal or vertical axis.

const (
	Horizontal Axis = 1 << iota
	Vertical
)

func (Axis) Cross

func (a Axis) Cross(p image.Point) int

Cross returns the value of p along the cross axis.

func (Axis) CrossAxis

func (a Axis) CrossAxis() Axis

CrossAxis returns the cross axis.

func (Axis) Main

func (a Axis) Main(p image.Point) int

Main returns the value of p along the axis.

func (Axis) MainCross

func (a Axis) MainCross(p image.Point) (int, int)

MainCross returns the main and cross axis values.

func (Axis) Point

func (a Axis) Point(x, y int) image.Point

Point returns p adjusted for the axis.

type Clickable

type Clickable struct {
	Button ebiten.MouseButton
	// State tracks the Pressed, Hovering, Clicked and DoubleClicked states.
	State MouseState
}

Clickable keeps track of the mouse gestures in the widget's area.

func (*Clickable) Draw

func (c *Clickable) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*Clickable) Pressed

func (c *Clickable) Pressed() image.Point

Pressed is the last pressed cursor position.

func (*Clickable) Size

func (c *Clickable) Size(viewsize image.Point) image.Point

type ClickableList

type ClickableList struct {
	Button ebiten.MouseButton
	WidgetList
	// contains filtered or unexported fields
}

ClickableList wraps a WidgetList and adds a Clickable to all of its elements.

func (*ClickableList) At

func (c *ClickableList) At(index int) Widget

func (*ClickableList) StateAt

func (c *ClickableList) StateAt(index int) *MouseState

StateAt returns the MouseState at the given index, nil if the index is invalid.

type Cursor

type Cursor struct {
	// Blink is in milliseconds.
	Blink time.Duration
	Color color.Color
	Dims  image.Point
}

Cursor defines the attributes of an editor's cursor.

type Debug

type Debug struct {
	Color color.Color
	Widget
}

Debug a widget by wrapping its content in a colored rectangle. The default color is red.

func (Debug) Draw

func (d Debug) Draw(screen *ebiten.Image, viewport image.Rectangle)

type Flex

type Flex struct {
	Axis Axis
	// Alignment on the cross axis.
	Alignment Alignment
	// Spacing along the main axis.
	Spacing Spacing
	// Children is one of:
	//  - WidgetList
	//  - []any, where any can be is one of:
	//    - Widget
	//    - FlexChild
	//    - nil
	Children any
}

Flex draws widgets along the given axis.

func (Flex) Draw

func (f Flex) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Flex) Size

func (f Flex) Size(viewsize image.Point) image.Point

type FlexChild

type FlexChild struct {
	Weight float32
	Widget
}

FlexChild defines how a flex child is drawn. A zero weight means that the widget is drawn with the remaining space, else its container space is relative to its weight and the sum of all weights.

type Image

type Image struct {
	Img    *ebiten.Image
	ScaleX float64
	ScaleY float64
}

Image turns an ebiten.Image into a Widget.

func (Image) Draw

func (i Image) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Image) Size

func (i Image) Size(viewsize image.Point) image.Point

type Inset

type Inset struct {
	Top    int
	Bottom int
	Left   int
	Right  int
	Widget
}

Inset a widget according to its values.

func (Inset) Apply

func (in Inset) Apply(w Widget) Widget

func (Inset) Draw

func (in Inset) Draw(screen *ebiten.Image, viewport image.Rectangle)

type Label

type Label struct {
	Alignment Alignment
	Font      font.Face
	Color     color.Color
	Text      string
}

Label displays the content of Text horizontally.

func (Label) Draw

func (l Label) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Label) Size

func (l Label) Size(viewsize image.Point) image.Point

type LineEditor

type LineEditor struct {
	Font   font.Face
	Color  color.Color
	Click  Clickable
	Cursor Cursor
	// contains filtered or unexported fields
}

LineEditor for single line text.

func (*LineEditor) DeFocus

func (ed *LineEditor) DeFocus()

DeFocus takes the editor out of focus.

func (*LineEditor) Draw

func (ed *LineEditor) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*LineEditor) Focus

func (ed *LineEditor) Focus()

Focus puts the editor in focus.

func (*LineEditor) IsEscaped

func (ed *LineEditor) IsEscaped() bool

IsEscaped returns whether the content was escaped (hit ESC).

func (*LineEditor) IsFocused

func (ed *LineEditor) IsFocused() bool

IsFocused returns whether the editor is in focus.

func (*LineEditor) IsSubmitted

func (ed *LineEditor) IsSubmitted() bool

IsSubmitted returns whether the content was submitted (hit Enter).

func (*LineEditor) Len

func (ed *LineEditor) Len() int

Len returns the number of runes currently stored in the editor.

func (*LineEditor) SetCursorPos

func (ed *LineEditor) SetCursorPos(i int)

SetCursorPos sets the cursor at the given position. An invalid position has no effect.

func (*LineEditor) SetValue

func (ed *LineEditor) SetValue(v string)

SetValue sets the content of the editor.

func (*LineEditor) Size

func (ed *LineEditor) Size(viewsize image.Point) image.Point

func (*LineEditor) Submit

func (ed *LineEditor) Submit()

Submit the content of the editor.

func (*LineEditor) Value

func (ed *LineEditor) Value() string

Value returns the current content of the editor.

type List

type List struct {
	Axis        Axis
	Widgets     WidgetList
	First       int
	FirstOffset int
	Last        int
}

List fills its viewport with widgets and allows scrolling them.

func (*List) Draw

func (l *List) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*List) Size

func (l *List) Size(viewsize image.Point) image.Point

type MouseState

type MouseState uint8

MouseState stores the current state(s) of the mouse. Use its Has method to check state presence.

const (
	Normal MouseState = iota
	Hovering
	Pressed
	Clicked
	DoubleClicked
	Dragging
	Dropped
	Disabled
)

func (*MouseState) Has

func (ms *MouseState) Has(state MouseState) bool

Has returns whether the state is present.

func (MouseState) String

func (ms MouseState) String() string

type Outset

type Outset struct {
	Top    int
	Bottom int
	Left   int
	Right  int
	Widget
}

Outset a widget according to its values.

func (Outset) Apply

func (out Outset) Apply(w Widget) Widget

func (Outset) Draw

func (out Outset) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Outset) Size

func (out Outset) Size(viewsize image.Point) image.Point

type Pad

type Pad image.Point

Pad does not draw anything but takes up space. Negative or zero values make Pad use the viewport's.

func (Pad) Draw

func (p Pad) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Pad) Size

func (p Pad) Size(viewsize image.Point) image.Point

type Path

type Path struct {
	Path   vector.Path
	Color  color.Color
	Stroke *vector.StrokeOptions
	// contains filtered or unexported fields
}

Path caches a vector.Path.

func (*Path) Draw

func (p *Path) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*Path) Reset

func (p *Path) Reset()

Reset the cache for a new path.

NB. not required for a color change.

func (*Path) Size

func (p *Path) Size(viewsize image.Point) image.Point

type Place

type Place struct {
	Position
	Widget
}

Place a widget using the position relative to its container.

func (Place) Apply

func (p Place) Apply(w Widget) Widget

func (Place) Draw

func (p Place) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Place) Size

func (p Place) Size(viewsize image.Point) image.Point

type Position

type Position uint8

Position an item relative to its container.

const (
	TopLeft Position = iota
	Top
	TopRight
	Right
	BottomRight
	Bottom
	BottomLeft
	Left
	Center
)

func (Position) Offset

func (p Position) Offset(cont, dims image.Rectangle) image.Point

Offset returns the position for a widget of dimensions `dims` in a container of dimensions `cont`.

type RRectangle

type RRectangle struct {
	Radius int
	// Width for the rectangle, if negative, the rectangle is filled.
	Width int
	Color color.Color
	Dims  image.Point
}

RRectangle is a rectangle with rounded corners.

func (RRectangle) Draw

func (rr RRectangle) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (RRectangle) Size

func (rr RRectangle) Size(viewsize image.Point) image.Point

type Slice

type Slice []Widget

Slice turns a slice of widgets into a WidgetList.

func (Slice) At

func (s Slice) At(index int) Widget

func (Slice) Len

func (s Slice) Len() int

type Slider

type Slider struct {
	Axis  Axis
	Drag  Clickable
	Value float32
	// contains filtered or unexported fields
}

Slider updates its Value field when its area is dragged. The value is between 0.0 and 1.0 and, while dragging, corresponds to the mouse pointer current position within the widget's area along the main axis.

func (*Slider) Draw

func (f *Slider) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*Slider) Len

func (f *Slider) Len(viewsize image.Point) int

func (*Slider) Size

func (f *Slider) Size(viewsize image.Point) image.Point

type Spacing

type Spacing uint8

Spacing between widgets in a Flex.

const (
	// Ending adds space at the end.
	Ending Spacing = iota
	// Beginning adds space at the start.
	Beginning
	// Sides splits space at the start and end.
	Sides
	// Around splits space between elements, and half of that for start and end.
	Around
	// Between splits space between elements.
	Between
	// Evenly splits space evenly between elements, start and end.
	Evenly
)

func (Spacing) Space

func (sp Spacing) Space(avail, n int) (start, between int)

Space returns the space at the start and between `n` children.

type Stack

type Stack []any

Stack is a slice of:

  • Widget
  • StackChild
  • nil

func (Stack) Draw

func (s Stack) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Stack) Size

func (s Stack) Size(viewsize image.Point) image.Point

type StackChild

type StackChild struct {
	// Expand sets the viewport/viewsize from the stack size
	// for the given axis/axes.
	Expand Axis
	Widget Widget
}

Stack widgets on top of each other (last one on top).

type Tile

type Tile struct {
	Position Position
	Source   *ebiten.Image
}

Tile an image in its viewport.

func (Tile) Draw

func (t Tile) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Tile) Size

func (t Tile) Size(viewsize image.Point) image.Point

type Tree

type Tree[T comparable] struct {
	Button ebiten.MouseButton
	Tree   TreeIf[T]
	// List's Widgets field will be automatically set.
	List List
	// contains filtered or unexported fields
}

Tree fills its viewport with the content of a tree-like data structure. The tree is interactive where parent nodes can expand when clicked to display their children.

func (*Tree[T]) Click

func (t *Tree[T]) Click(v T)

Click on element v, which opens or closes it if it is a parent node.

func (*Tree[T]) Draw

func (t *Tree[T]) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (*Tree[T]) IsOpened

func (t *Tree[T]) IsOpened(v T) bool

IsOpened returns the current open state of element v.

func (*Tree[T]) Size

func (t *Tree[T]) Size(viewsize image.Point) image.Point

type TreeIf

type TreeIf[T comparable] interface {
	// Root elements of the tree.
	Root() TreeNodeIterator[T]
	// Children for a given node.
	Children(node T) TreeNodeIterator[T]
	// At returns the widget to be displayed for an element.
	// click is nil if the node is a leaf.
	// The returned widget should also display the click widget.
	At(node T, click *Clickable, depth uint16) (content Widget)
}

TreeIf is the interface to represent a tree-like data structure. T is the type used to uniquely identify any element in the tree.

type TreeNodeIterator

type TreeNodeIterator[T comparable] interface {
	Len() int
	At(int) T
}

TreeNodeIterator provides the elements for a root or parent node.

type View

type View struct {
	Dims image.Point
	Widget
}

View restricts the view of a widget. If a dimension is <= 0 then the widget's value is used.

func (View) Apply

func (v View) Apply(w Widget) Widget

func (View) Draw

func (v View) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (View) Size

func (v View) Size(viewsize image.Point) image.Point

type Widget

type Widget interface {
	Size(viewsize image.Point) image.Point
	Draw(screen *ebiten.Image, viewport image.Rectangle)
}

type WidgetList

type WidgetList interface {
	Len() int
	At(index int) Widget
}

type Wrap

type Wrap struct {
	Axis      Axis
	Alignment Alignment
	Widgets   WidgetList
}

Wrap widgets along an axis. They must all have the same size.

func (Wrap) Draw

func (w Wrap) Draw(screen *ebiten.Image, viewport image.Rectangle)

func (Wrap) Size

func (w Wrap) Size(viewsize image.Point) image.Point

Directories

Path Synopsis
themes

Jump to

Keyboard shortcuts

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