ui

package
v0.0.0-...-acf18e3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICON_PLAY_TOGGLE  = string(0x25ba) + string(0x007c)
	ICON_SLOW_DOWN    = "-"
	ICON_SPEED_UP     = "+"
	ICON_RESET_STATE  = string(0x00d8)
	ICON_RANDOM_STATE = string(0x2591) + string(0x2591)
	ICON_FF_I         = "I"
	ICON_FF_X         = "X"
	ICON_FF_L         = "L"
	ICON_FF_C         = "C"
	ICON_FF_M         = "M"
)

Variables

This section is empty.

Functions

func NewButton

func NewButton(bt *theme.ButtonTheme, font *font.Face, text string, c *Controller, s UISignal) *widget.Button

Returns the new widget.Button given font, text to display, Controller and signal corresponding with the Button.

func NewButtonCluster

func NewButtonCluster() *widget.Container

Returns a pointer to the container designed to hold buttons that serve similar functions.

func NewLabel

func NewLabel(lt *theme.LabelTheme, font *font.Face, text string) *widget.Label

Creates a label with specified text and returns a pointer to it.

func NewLabeledDisplay

func NewLabeledDisplay(lt *theme.LabelTheme, font *font.Face, labelText string) (*widget.Container, *widget.Label)

Creates a special kind of label. It consists of 2 widget.Label instances. One of them serves as a title, denoting a type of information displayed and another is holding value that can be changed. It is used to provide insight to game variables such as current generation number, current speed or zoom level. This function returns a container holding both labels and the label serving as a value holder. Accepts the title text.

func NewTextInput

func NewTextInput(tit *theme.TextInputTheme, font *font.Face, placeholder, text string, c *Controller, s UISignal) *widget.TextInput

Returns new widget.TextInput. Accepts font, placeholder (text displayed when empty), text to display, Controller and UISignal associated with the TextInput.

Types

type Controller

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

Controller for the UI.

func NewController

func NewController(rules string) *Controller

Creates a new Controller structure.

func (*Controller) ClearLMBPointer

func (c *Controller) ClearLMBPointer()

Sets c.lmbDownOn to nil.

func (*Controller) Emit

func (c *Controller) Emit() *UIResponse

Emits the current UI state outwards in form of UIResponse.

func (*Controller) GetRules

func (c *Controller) GetRules() string

func (*Controller) GetSignal

func (c *Controller) GetSignal() UISignal

func (*Controller) IsLMBDownOn

func (c *Controller) IsLMBDownOn(w *widget.Widget) bool

Returns true if w and c.lmbDownOn point to the same widget.

func (*Controller) SetLMBDownOn

func (c *Controller) SetLMBDownOn(w *widget.Widget)

Stores the pointer to w in c.lmbDownOn.

func (*Controller) SetRules

func (c *Controller) SetRules(rules string)

func (*Controller) SetSignal

func (c *Controller) SetSignal(s UISignal)

type UI

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

Top structure of User Interface.

func NewUI

func NewUI(uit *theme.UITheme, lang *lang.Language, rules string) (*UI, error)

Creates UI elements: containers, widgets and the corresponding Controller.

func (*UI) Clicked

func (ui *UI) Clicked() bool

Called on click. Returns true if a mouse cursor is inside one of the panels.

func (*UI) Draw

func (ui *UI) Draw(screen *ebiten.Image)

Draws UI onto the screen.

func (*UI) SetRules

func (ui *UI) SetRules(rules string)

Sets the contents of the ui.rules. If user specifies incorrect rules, this method is called to revert to the previous ones.

func (*UI) Update

func (ui *UI) Update() *UIResponse

Updates the UI. Returns UIResponse if widget was interacted with.

func (*UI) UpdateGenValue

func (ui *UI) UpdateGenValue(new uint64)

Sets the generation label text to new value.

func (*UI) UpdateSpeedValue

func (ui *UI) UpdateSpeedValue(new int)

Sets the current speed label text to new value.

func (*UI) UpdateZoomValue

func (ui *UI) UpdateZoomValue(new float32)

Sets the current zoom label text to new value.

type UIResponse

type UIResponse struct {
	// Current rules read from the TextInput
	Rules string

	// Signal passed since last Controller.Emit call
	Signal UISignal
}

Represents the state of the Controller. It is emitted outwards on Controller.Emit call.

type UISignal

type UISignal uint8

Signal received by Controller. Each signal corresponds with specific widget and allows the Game to determine in what way its state should be modified.

const (
	// No signal is currently stored (UI was not interacted with)
	NONE UISignal = iota

	// Toggle Play / Pause
	PLAY_TOGGLE

	// Decrease speed
	SLOW_DOWN

	// Increase speed
	SPEED_UP

	// Reset the world (set the state of all cells to DEAD)
	RESET_STATE

	// Set random state
	RANDOM_STATE

	// Fast forward 1 generation
	FF_I

	// Fast forward 10 generations
	FF_X

	// Fast forward 50 generations
	FF_L

	// Fast forward 100 generations
	FF_C

	// Fast forward 1000 generations
	FF_M

	// Indicates that new rules were requested
	NEW_RULES
)

Jump to

Keyboard shortcuts

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