ui

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ui provides interactive user-interface components.

Button is a clickable element with Normal/Hovered/Pressed states. Dialog presents a modal overlay with a title, contextual text, and selectable options, each with a callback. Both components handle their own input processing and rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// Label is the display text for this button.
	Label string

	// ShortcutLabel is the text shown in brackets before the label (e.g., "1", "ESC").
	ShortcutLabel string

	// X is the left edge of the button in screen pixels.
	X float64

	// Y is the top edge of the button in screen pixels.
	Y float64

	// Width is the button width in screen pixels.
	Width float64

	// Height is the button height in screen pixels.
	Height float64

	// State is the current visual state of the button.
	State ButtonState
	// contains filtered or unexported fields
}

Button represents a clickable UI button with text, a keyboard shortcut label, and hover/press states.

func (*Button) Draw

func (b *Button) Draw(screen *ebiten.Image, fontSize int)

Draw renders the button on the screen.

func (*Button) Update

func (b *Button) Update(mouseX, mouseY float64, mousePressed bool)

Update calculates the button state from the current mouse position and click state. mouseX and mouseY are screen coordinates. mousePressed is true if the left mouse button is down.

type ButtonState

type ButtonState int

ButtonState represents the visual state of a button.

const (
	// ButtonStateNone is the default uninitialized button state.
	ButtonStateNone ButtonState = iota
	// ButtonStateNormal is the default button state.
	ButtonStateNormal
	// ButtonStateHovered is when the mouse cursor is over the button.
	ButtonStateHovered
	// ButtonStatePressed is when the button is being clicked.
	ButtonStatePressed
)

type Dialog

type Dialog struct {
	// Title is displayed at the top of the dialog.
	Title string

	// Context is optional text displayed between the title and options.
	Context string

	// Options is the list of selectable options.
	Options []DialogOption

	// OnCancel is called when the dialog is dismissed with ESC.
	OnCancel func()

	// SelectedIndex is the currently highlighted option (for keyboard navigation).
	SelectedIndex int
	// contains filtered or unexported fields
}

Dialog is a modal UI overlay with a title, optional context text, and selectable options.

func NewDialog

func NewDialog(title string, options []DialogOption, onCancel func()) *Dialog

NewDialog creates a dialog with the given title, options, and cancel callback.

func (*Dialog) Draw

func (d *Dialog) Draw(screen *ebiten.Image)

Draw renders the dialog on the screen.

func (*Dialog) SetScreenSize

func (d *Dialog) SetScreenSize(width, height int)

SetScreenSize updates the screen dimensions used for centering the dialog.

func (*Dialog) Update

func (d *Dialog) Update() bool

Update processes input for the dialog. Returns true if an option was selected or the dialog was cancelled.

type DialogOption

type DialogOption struct {
	// Label is the display text for this option.
	Label string

	// Detail is optional secondary text shown to the right (e.g., a price or cooldown).
	Detail string

	// OnSelect is called when this option is selected.
	OnSelect func()
}

DialogOption represents a selectable option in the dialog.

Jump to

Keyboard shortcuts

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