btn

package
v2.3.2-beta Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIntText

func NewIntText(f *render.Font, str *int, x, y float64, layers ...int) *entities.Doodad

NewIntText creates some uitext from an integer

func NewRawText

func NewRawText(f *render.Font, str fmt.Stringer, x, y float64, layers ...int) *entities.Doodad

NewRawText creates some uitext from a stringer

func NewText

func NewText(f *render.Font, str string, x, y float64, layers ...int) *entities.Doodad

NewText creates some uitext

func Revert

func Revert(b Btn, n int) error

Revert will check that the given button's renderable can have modifications reverted, then revert the last n modifications.

Types

type Box

type Box struct {
	entities.Solid
	mouse.CollisionPhase
	// contains filtered or unexported fields
}

Box is a basic implementation of btn

func NewBox

func NewBox(cid event.CID, x, y, w, h float64, r render.Renderable, layers ...int) *Box

NewBox creates a new btn.box

func (*Box) GetRenderable

func (b *Box) GetRenderable() render.Renderable

GetRenderable returns the box's renderable

func (*Box) Init

func (b *Box) Init() event.CID

Init intializes the btn.box

func (*Box) Metadata

func (b *Box) Metadata(k string) (v string, ok bool)

Metadata accesses the value, and whether it existed, for a given metadata key

func (*Box) SetMetadata

func (b *Box) SetMetadata(k, v string)

SetMetadata sets the metadata for some key to some value. Empty value strings will not be stored.

type Btn

type Btn interface {
	event.Caller
	render.Positional
	GetRenderable() render.Renderable
	GetSpace() *collision.Space
	SetMetadata(string, string)
	Metadata(string) (string, bool)
}

Btn defines a button for use in the UI

func New

func New(opts ...Option) Btn

New creates a button with the given options and defaults for all variables not set.

type Generator

type Generator struct {
	X, Y           float64
	W, H           float64
	TxtX, TxtY     float64
	Color          color.Color
	Color2         color.Color
	ProgressFunc   func(x, y, w, h int) float64
	Mod            mod.Transform
	R              render.Modifiable
	R1             render.Modifiable
	R2             render.Modifiable
	RS             []render.Modifiable
	Cid            event.CID
	Font           *render.Font
	Layers         []int
	Text           string
	Children       []Generator
	Bindings       map[string][]event.Bindable
	Trigger        string
	Toggle         *bool
	ListChoice     *int
	Group          *Group
	DisallowRevert bool
}

A Generator defines the variables used to create buttons from optional arguments

func (Generator) Generate

func (g Generator) Generate() Btn

Generate creates a Button from a generator.

type Group

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

Group links several btns together

func (*Group) GetActive

func (g *Group) GetActive() Btn

GetActive returns the active btn from the group

type Option

type Option func(Generator) Generator

An Option is used to populate generator fields prior to generation of a button

func AddChildren

func AddChildren(cg ...Generator) Option

AddChildren adds a generator to create a child btn

func And

func And(opts ...Option) Option

And combines a variadic number of options

func AndMod

func AndMod(m mod.Transform) Option

AndMod combines the input modification with whatever existing modifications exist for the generator, as opposed to Mod which resets previous modifications.

func Binding

func Binding(s string, bnd event.Bindable) Option

Binding appends a function to be called when a specific event is triggered.

func CID

func CID(c event.CID) Option

CID sets the starting CID of the button to be generated

func Clear

func Clear() Option

Clear resets the button to be empty

func Click

func Click(bnd event.Bindable) Option

Click appends a function to be called when the button is clicked on.

func Color

func Color(c color.Color) Option

Color sets the colorboxes color for the button to be generated

func DisallowRevert

func DisallowRevert() Option

Todo: change this to AllowRevert, and reverse the default behavior

func Font

func Font(f *render.Font) Option

Font sets the font for the text of the button to be generated

func Height

func Height(h float64) Option

Height sets the Height of the button to be generated

func Layers

func Layers(ls ...int) Option

Layers sets the layer of the button to be generated

func Mod

func Mod(m mod.Transform) Option

Mod sets the modifications to apply to the initial color box for the button to be generated

func Offset

func Offset(x, y float64) Option

Offset increments the position of the button to be generated

func Pos

func Pos(x, y float64) Option

Pos sets the position of the button to be generated

func Renderable

func Renderable(r render.Modifiable) Option

Renderable sets a renderable to use as a base image for the button. Not compatible with Color / Toggle.

func Text

func Text(s string) Option

Text sets the text of the button to be generated

func Toggle

func Toggle(r1, r2 render.Modifiable, isChecked *bool) Option

Toggle sets that the type of the button toggles between two modifiables when it is clicked. The boolean behind isChecked is updated according to the state of the button. Todo: the copies here should be optional

func ToggleGroup

func ToggleGroup(gr *Group) Option

ToggleGroup sets the group that this button is linked with

func ToggleList

func ToggleList(chosen *int, rs ...render.Modifiable) Option

ToggleList sets the togglable choices for a button

func TxtOff

func TxtOff(x, y float64) Option

TxtOff sets the text offset of the button generator from the bottom left

func VGradient

func VGradient(c1, c2 color.Color) Option

VGradient creates a vertical color gradient for the btn

func Width

func Width(w float64) Option

Width sets the Width of the button to be generated

type TextBox

type TextBox struct {
	Box
	*render.Text
}

TextBox is a Box with an associated text element

func NewTextBox

func NewTextBox(cid event.CID, x, y, w, h, txtX, txtY float64,
	f *render.Font, r render.Renderable, layers ...int) *TextBox

NewTextBox creates a textbox

func (*TextBox) Init

func (b *TextBox) Init() event.CID

Init creates the CID

func (*TextBox) SetOffsets

func (b *TextBox) SetOffsets(txtX, txtY float64)

SetOffsets changes the text position within the box

func (*TextBox) SetPos

func (b *TextBox) SetPos(x, y float64)

SetPos acts as SetSpace does, overwriting entities.Solid.

func (*TextBox) SetSpace

func (b *TextBox) SetSpace(sp *collision.Space)

SetSpace overwrites entities.Solid, pointing this button to use the mouse collision Rtree instead of the entity collision space.

func (*TextBox) ShiftX

func (b *TextBox) ShiftX(x float64)

ShiftX shifts the box by x. The associated text is attached and so will be moved along by default

func (*TextBox) ShiftY

func (b *TextBox) ShiftY(y float64)

ShiftY shifts the box by y. The associated text is attached and so will be moved along by default

func (*TextBox) X

func (b *TextBox) X() float64

X pulls the x of the composed Box (disambiguation with the x of the text component)

func (*TextBox) Y

func (b *TextBox) Y() float64

Y pulls the y of the composed Box (disambiguation with the y of the text component)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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