magicform

package
v0.0.0-...-79996cc Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package magicform helps create simple form layouts with go/ui.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// Type may be inferred by presence of other params.
	Type Type

	// Set a text string and font for simple labels or paragraphs.
	Label string
	Font  render.Text

	// Easy button row: make Buttons an array of Button fields
	Buttons     []Field
	ButtonStyle *style.Button

	// Easy Paginator. DO NOT SUPERVISE, let the Create do so!
	Pager *ui.Pager

	// If you send a *ui.Frame to insert, the Type is inferred
	// to be Frame.
	Frame *ui.Frame

	// Variable bindings, the type may infer to be:
	BoolVariable *bool         // Checkbox
	TextVariable *string       // Textbox
	IntVariable  *int          // Textbox
	Options      []Option      // Selectbox
	SelectValue  interface{}   // Selectbox default choice
	Color        *render.Color // Color
	Readonly     bool          // draw the value as a flat label

	// For text-type fields, opt-in to let magicform prompt the
	// user using the game's developer shell.
	PromptUser func(answer string)

	// Tooltip to add to a form control.
	// Checkbox only for now.
	Tooltip ui.Tooltip // config for the tooltip only

	// Handlers you can configure
	OnSelect func(value interface{}) // Selectbox
	OnClick  func()                  // Button
}

Field for your form (or form-aligned label sections, etc.)

The type of Form control to render is inferred based on bound variables and other configuration.

func (Field) Infer

func (field Field) Infer() Type

Infer the type if the field was of type Auto.

Returns the first Type inferred from the field by checking in this order:

- Frame if the field has a *Frame - Checkbox if there is a *BoolVariable - Selectbox if there are Options - Textbox if there is a *TextVariable - Text if there is a Label

May return Auto if none of the above and be ignored.

type Form

type Form struct {
	Supervisor *ui.Supervisor // Required for most useful forms
	Engine     render.Engine

	// For vertical forms.
	Vertical   bool
	LabelWidth int // size of left frame for labels.
	PadY       int // spacer between (vertical) forms
	PadX       int
}

Form configuration.

func (Form) Create

func (form Form) Create(into *ui.Frame, fields []Field)

Create the form field and populate it into the given Frame.

Renders the form vertically.

type Option

type Option struct {
	Value     interface{}
	Label     string
	Separator bool
}

Option used in Selectbox or Radiobox fields.

type Type

type Type int
const (
	Auto   Type = iota
	Text        // free, wide Label row
	Frame       // custom frame from the caller
	Button      // Single button with a label
	Value       // a Label & Value row (value not editable)
	Textbox
	Checkbox
	Radiobox
	Selectbox
	Color
)

Jump to

Keyboard shortcuts

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