widgets

package
v0.0.0-...-5d198e7 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(r *sdl.Renderer)

Types

type Event

type Event uint8

I want to try and simplify event handling for widgets. Not sure this counts.

const (
	ButtonUp Event = iota
	ButtonDown
	ButtonLeft
	ButtonRight
	ButtonA
	ButtonB
	ButtonSelect
	ButtonStart
)

type Group

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

Group adds a list of children to widgets embedding it, as well as an Add() method to append children to the list, and event dispatching.

func NewGroup

func NewGroup(rect *sdl.Rect, children []Widget, props ...Properties) *Group

func (*Group) Add

func (g *Group) Add(child Widget)

Add appends a child widget to the internal list of children.

func (*Group) Clear

func (g *Group) Clear()

Clear removes all children from the group and clears their textures.

func (Group) Destroy

func (w Group) Destroy()

Destroy frees the widget's internal texture.

func (*Group) ProcessEvent

func (g *Group) ProcessEvent(e Event) bool

ProcessEvent calls ProcessEvent for each child widget until one of them returns true. If none return true, false is returned.

func (Group) Texture

func (w Group) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type HorizontalLayout

type HorizontalLayout struct {
	*Group
}

HorizontalLayout renders its children widgets from left to right, horizontally centered.

func NewHorizontalLayout

func NewHorizontalLayout(size *sdl.Rect, children []Widget, props ...Properties) *HorizontalLayout

func (*HorizontalLayout) Add

func (l *HorizontalLayout) Add(child Widget)

func (HorizontalLayout) Destroy

func (w HorizontalLayout) Destroy()

Destroy frees the widget's internal texture.

func (*HorizontalLayout) ProcessEvent

func (l *HorizontalLayout) ProcessEvent(e Event) bool

func (HorizontalLayout) Texture

func (w HorizontalLayout) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type Input

type Input struct {
	*HorizontalLayout

	Text string // Input value as text, set at confirm time
	// contains filtered or unexported fields
}

func NewInput

func NewInput(sizeHint *sdl.Rect, size int, charset string, onConfirm func()) *Input

NewInput instantiates an Input widget with the given number of editable characters. Each character can be selected within the given charset. By default, the first character of the string given as a charset is used.

func (*Input) Confirm

func (in *Input) Confirm()

func (Input) Destroy

func (w Input) Destroy()

Destroy frees the widget's internal texture.

func (*Input) Next

func (in *Input) Next()

func (*Input) Prev

func (in *Input) Prev()

func (*Input) ProcessEvent

func (in *Input) ProcessEvent(e Event) bool

func (Input) Texture

func (w Input) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type Label

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

func NewLabel

func NewLabel(sizeHint *sdl.Rect, text string, props ...Properties) *Label

TODO: why couldn't these be methods of a global UI object abstracting the renderer?

I'd just need to move all widgets back up to the ui package.

TODO: actual font size

func (Label) Destroy

func (w Label) Destroy()

Destroy frees the widget's internal texture.

func (Label) ProcessEvent

func (w Label) ProcessEvent(e Event) bool

ProcessEvent should be overridden in widgets that actually do process events. The default implementation always returns false to indicate no event is handled.

func (Label) Texture

func (w Label) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type Menu struct {
	*VerticalLayout
	// contains filtered or unexported fields
}

Menu widget displaying a list of potential choices, each of which should map to some kind of Action.

func NewMenu

func NewMenu(sizeHint *sdl.Rect) *Menu
func (m *Menu) AddChoice(title string, action func())
func (m *Menu) Confirm()
func (w Menu) Destroy()

Destroy frees the widget's internal texture.

func (m *Menu) Down()
func (m *Menu) ProcessEvent(e Event) bool
func (m *Menu) Select(index uint)
func (w Menu) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

func (m *Menu) Up()

type Properties

type Properties struct {
	Font      *ttf.Font
	TitleFont *ttf.Font // FIXME: only one Font property, to be set to small or large.

	BgColor sdl.Color // FIXME: OutlineColor
	FgColor sdl.Color

	Background sdl.Color // Background color (default is transparent)

	Margin int32 // TODO: individual horizontal/vertical margin

	HorizontalAlign align.Align // Widget contents alignment (horizontal)
	VerticalAlign   align.Align // Widget contents alignment (vertical)

	// For debugging if nothing else.
	Border      int32
	BorderColor sdl.Color

	Zoom int // Zoom factor for the GameBoy display. Used for outlines, margins.
}

Properties stores useful configuration variables to be passed to all widgets at creation time. Internally uses SDL types for convenience. FIXME: separate actual widget properties (margin, background...) and configuration (Fg/BgColor, fonts...)

var DefaultProperties Properties

type Stack

type Stack struct {
	*Group
	// contains filtered or unexported fields
}

func NewStack

func NewStack(sizeHint *sdl.Rect, children []Widget, props ...Properties) *Stack

func (*Stack) Add

func (s *Stack) Add(w Widget)

Add appends the given widget to the stack's internal children, and shows it if it's the very first child to be added.

func (Stack) Destroy

func (w Stack) Destroy()

Destroy frees the widget's internal texture.

func (*Stack) ProcessEvent

func (s *Stack) ProcessEvent(e Event) bool

ProcessEvent calls ProcessEvent for the currently displayed widget if any.

func (*Stack) Show

func (s *Stack) Show(index uint)

Show sets the current index of the widget to be drawn and repaints the stack.

func (Stack) Texture

func (w Stack) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type VerticalLayout

type VerticalLayout struct {
	*Group
}

VerticalLayout renders its children widgets from top to bottom, vertically centered.

func NewVerticalLayout

func NewVerticalLayout(size *sdl.Rect, children []Widget, props ...Properties) *VerticalLayout

func (*VerticalLayout) Add

func (l *VerticalLayout) Add(child Widget)

func (VerticalLayout) Destroy

func (w VerticalLayout) Destroy()

Destroy frees the widget's internal texture.

func (VerticalLayout) Texture

func (w VerticalLayout) Texture() *sdl.Texture

Texture should be called by subclasses to apply unused properties like border to the widget's internal texture.

type Widget

type Widget interface {
	// ProcessEvent returns true if the widget caught and handled the event,
	// false if it did not.
	ProcessEvent(Event) bool

	// Texture return the widget's internal texture in its current state. This
	// call might modify the renderer's state if a widget redraws its texture
	// just-in-time.
	Texture() *sdl.Texture

	// Destroy releases all resources dynamically allocated by the widget, like
	// its internal texture.
	Destroy()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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