menu

package
v0.0.0-...-c712ff3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package menu provides various ways to draw a main menu and handle user input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	Text string
	Rect *sdl.Rect

	// Handler is executed when the user presses a submit key with this Button
	// selected.
	Handler func() error
}

Button stores the state and logic for a menu button.

type Menu interface {
	Font() *ttf.Font
	Buttons() []*Button
	CursorPos() int
	ResetCursor()

	CursorUp()
	CursorDown()
	CursorRect() (*sdl.Rect, error)

	AddButton(string, func() error)
	ClearButtons()
}

Menu represents a basic main menu with buttons aligned vertically. Other layouts may be supported later.

func NewMenu

func NewMenu(p NewMenuParams) (Menu, error)

NewMenu creates a game menu with a font and a set of buttons.

type NewMenuParams

type NewMenuParams struct {
	W        int32
	H        int32
	ButtonW  int32
	ButtonH  int32
	FontFile string
}

NewMenuParams stores the data required to create a game menu.

Jump to

Keyboard shortcuts

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