gebiten_ui

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

gebiten-ui

gebiten-ui is a small UI library for Ebitengine. It currently provides a GButton and GTextbox, plus a thing GFont wrapper around Ebitengine's text rendering.

Features

  • Common GWidget interface.
  • GButton with click handling and automatically centered label.
  • GTextureButton, a simple button that just registers clicks with no additional text drawing.
  • GTextbox, a single line textbox with focus, caret, text editing and y-axis centering.
  • GHoverTexture, a texture that displays a hover box(which contains some text and another texture) below the texture, and if not possible, above it.
  • GFont, a utility wrapper for drawing text.

Usage

A more complete example is available in cmd/main.go

import (
    gebitenui "gebiten-ui"
)

texture := ...

fnt, _ := gebitenui.NewGFont("font.ttf", 24)
btn, _ := gebitenui.NewButton("Press Me!", 0, 0, texture, fnt, func () {
    // do something
})

Inside your Update() function you must call the widget's Update() function

btn.Update()

Inside your Draw() function you must call the widget's Draw() function

btn.Draw(screen)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GButton

type GButton struct {
	// contains filtered or unexported fields
}

func NewButton

func NewButton(text string, x, y float64, tex *ebiten.Image, font *GFont, onClick GButtonClick) (*GButton, error)

NewButton checks that the string fits within the texture then return a new GButton, if you don't want bounds checks you can use NewButtonNoCheck

func NewButtonNoCheck

func NewButtonNoCheck(text string, x, y float64, tex *ebiten.Image, font *GFont, onClick GButtonClick) *GButton

NewButtonNoCheck builds a GButton without checking bounds of string against texture

func (*GButton) Draw

func (gb *GButton) Draw(screen *ebiten.Image)

Draw draws the button and attempts to center label within texture

func (*GButton) Update

func (gb *GButton) Update()

type GButtonClick

type GButtonClick func()

type GFont

type GFont struct {
	// contains filtered or unexported fields
}

GFont thin wrapper around ebiten text drawing mainly meant to be used to pass to other gebitenui components, but can be used independently if desired

func NewGFont

func NewGFont(ttfPath string, size float64) (*GFont, error)

func (*GFont) Draw

func (gf *GFont) Draw(screen *ebiten.Image, msg string, x, y float64, color color.Color)

func (*GFont) MeasureString

func (gf *GFont) MeasureString(msg string) (float64, float64)

type GHoverTexture added in v0.0.6

type GHoverTexture struct {
	// contains filtered or unexported fields
}

func NewHoverTexture added in v0.0.6

func NewHoverTexture(x, y, maxPosY float64, tex *ebiten.Image, hoverMsg *string, hoverTex *ebiten.Image, font *GFont, hoverTextColor color.Color) *GHoverTexture

func (*GHoverTexture) Draw added in v0.0.6

func (ght *GHoverTexture) Draw(screen *ebiten.Image)

func (*GHoverTexture) Update added in v0.0.6

func (ght *GHoverTexture) Update()

type GTextbox

type GTextbox struct {
	// contains filtered or unexported fields
}

GTextbox centers text on the Y axis and accepts a text x/y offset

func NewTextBox

func NewTextBox(x, y float64, maxTextLen int, tex *ebiten.Image, font *GFont, textOffsetX, textOffsetY float64, onChange GTextboxOnChange) *GTextbox

NewTextBox creates a new GTextBox

func (*GTextbox) Draw

func (gt *GTextbox) Draw(screen *ebiten.Image)

func (*GTextbox) Update

func (gt *GTextbox) Update()

type GTextboxOnChange added in v0.0.3

type GTextboxOnChange func(newText string)

type GTextureButton added in v0.0.5

type GTextureButton struct {
	// contains filtered or unexported fields
}

func NewTextureButton added in v0.0.5

func NewTextureButton(x, y float64, tex *ebiten.Image, onClick GButtonClick) *GTextureButton

NewTextureButton creates a new GTextureButton

func (*GTextureButton) Draw added in v0.0.5

func (gtb *GTextureButton) Draw(screen *ebiten.Image)

func (*GTextureButton) Update added in v0.0.5

func (gtb *GTextureButton) Update()

type GTextureButtonClick added in v0.0.5

type GTextureButtonClick func()

type GWidget

type GWidget interface {
	Update()
	Draw(screen *ebiten.Image)
}

type Vec2

type Vec2 struct {
	X float64
	Y float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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