eform

package
v0.0.0-...-911c31e Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// Text holds the text displayed on the button. It may use Minecraft formatting codes and may have
	// newlines.
	Text string
	// Image holds a path to an image for the button. The Image may either be a URL pointing to an image,
	// such as 'https://someimagewebsite.com/someimage.png', or a path pointing to a local asset, such as
	// 'textures/blocks/grass_carried'.
	Image string
}

Button represents a button added to a Menu or Modal form. The button has text on it and an optional image, which may be either retrieved from a website or the local assets of the game.

func NewButton

func NewButton(text, image string) Button

NewButton creates and returns a new Button using the text and image passed.

func NoButton

func NoButton() Button

NoButton returns a Button which may be used as a default 'no' button for a modal form.

func YesButton

func YesButton() Button

YesButton returns a Button which may be used as a default 'yes' button for a modal form.

func (Button) MarshalJSON

func (b Button) MarshalJSON() ([]byte, error)

MarshalJSON ...

type Custom

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

Custom represents a form that may be sent to a player and has fields that should be filled out by the player that the form is sent to.

func NewCustom

func NewCustom(title ...any) Custom

NewCustom creates a new (custom) form with the title passed and returns it. The title is formatted according to the rules of fmt.Sprintln.

func (Custom) Elements

func (f Custom) Elements() []Element

Elements returns a list of all elements passed in WithElements.

func (Custom) MarshalJSON

func (f Custom) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Custom) OnClose

func (f Custom) OnClose(c Handler) Custom

OnClose creates a copy of the Menu form and set the form close callback to the passed one.

func (Custom) OnSubmit

func (f Custom) OnSubmit(c interface{}) Custom

OnSubmit creates a copy of the Menu form and set the form submit callback to the passed one. will panic if passing c isn't a func

func (Custom) SubmitJSON

func (f Custom) SubmitJSON(b []byte, submitter Submitter) error

SubmitJSON submits a JSON data slice to the form. The form will check all values in the JSON array passed, making sure their values are valid for the form's elements. If the values are valid and can be parsed properly, the fields of the data will be filled out, and the onSubmit callback will be called.

func (Custom) Title

func (f Custom) Title() string

Title returns the formatted title passed when the form was created using NewCustom().

func (Custom) WithElements

func (f Custom) WithElements(elem ...Element) Custom

WithElements creates a copy of the Custom form and append the elements passed.

type Dropdown struct {
	// Text is the text displayed over the dropdown element. The text may contain Minecraft formatting codes.
	Text string
	// Options holds a list of options that a Submitter may select. The order of these options is retained
	// when shown to the submitter of the form.
	Options []string
	// DefaultIndex is the index in the Options slice that is used as default. When sent to a Submitter, the
	// value at this index in the Options slice will be selected.
	DefaultIndex int
}

Dropdown represents a dropdown which, when clicked, opens a window with the options set in the Options field. Submitters may select one of the options.

func NewDropdown

func NewDropdown(text string, options []string, defaultIndex int) Dropdown

NewDropdown creates and returns new Dropdown using the values passed.

func (d Dropdown) MarshalJSON() ([]byte, error)

MarshalJSON ...

type Element

type Element interface {
	json.Marshaler
	// contains filtered or unexported methods
}

Element represents an element that may be added to a Form. Any of the types in this package that implement the element interface may be used as struct fields when passing the form structure to form.NewCustom().

type Form

type Form interface {
	json.Marshaler
	SubmitJSON(b []byte, submitter Submitter) error
	// contains filtered or unexported methods
}

Form represents a form that may be sent to a Submitter. The three types of forms, custom forms, menu forms and modal forms implement this interface.

type Handler

type Handler func(Submitter)

Handler is closure used in form closing, button click

func (Handler) Call

func (c Handler) Call(s Submitter)

type Input

type Input struct {
	// Text is the text displayed over the input element. The text may contain Minecraft formatting codes.
	Text string
	// Default is the default value filled out in the input. The user may remove this value and fill out its
	// own text. The text may contain Minecraft formatting codes.
	Default string
	// Placeholder is the text displayed in the input box if it does not contain any text filled out by the
	// user. The text may contain Minecraft formatting codes.
	Placeholder string
}

Input represents a text input box element. Submitters may write any text in these boxes with no specific length.

func NewInput

func NewInput(text, defaultValue, placeholder string) Input

NewInput creates and returns a new Input with the values passed.

func (Input) MarshalJSON

func (i Input) MarshalJSON() ([]byte, error)

MarshalJSON ...

type Label

type Label struct {
	// Text is the text held by the label. The text may contain Minecraft formatting codes.
	Text string
}

Label represents a static label on a form. It serves only to display a box of text, and users cannot submit values to it.

func NewLabel

func NewLabel(text string) Label

NewLabel creates and returns a new Label with the values passed.

func (Label) MarshalJSON

func (l Label) MarshalJSON() ([]byte, error)

MarshalJSON ...

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

func NewMenu

func NewMenu(title ...any) Menu

NewMenu creates a new Menu form. The title passed is formatted following the rules of fmt.Sprintln.

func (m Menu) Body() string

Body returns the formatted text in the body passed to the menu using WithBody().

func (m Menu) Buttons() []Button

Buttons returns a list of all buttons of the Menu. It is appended by calling WithButton.

func (m Menu) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (m Menu) OnClose(onClose Handler) Menu

OnClose creates a copy of the Menu form and set the form close callback to the passed one.

func (m Menu) SubmitJSON(b []byte, submitter Submitter) error

SubmitJSON submits a JSON value to the menu, containing the index of the button clicked.

func (m Menu) Title() string

Title returns the formatted title passed to the menu upon construction using NewMenu().

func (m Menu) WithBody(body ...any) Menu

WithBody creates a copy of the Menu form and changes its body to the body passed, after which the new Menu form is returned. The text is formatted following the rules of fmt.Sprintln.

func (m Menu) WithButton(btn Button, onClick Handler) Menu

WithButton creates a copy of the Menu form and appends the button passed to the existing buttons, after which the new Menu form is returned.

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

Modal represents a modal form. These forms have a body with text and two buttons at the end, typically one for Yes and one for No. These buttons may have custom text, but can, unlike with a Menu form, not have images next to them.

func NewModal

func NewModal(title ...any) Modal

NewModal creates a new Modal form. The title passed is formatted following the fmt.Sprintln rules. Default buttons are 'yes' and 'no'

func (Modal) Body

func (m Modal) Body() string

Body returns the formatted text in the body passed to the menu using WithBody().

func (Modal) Buttons

func (m Modal) Buttons() []Button

Buttons returns a list of all buttons of the Modal form, which will always be a total of two buttons.

func (Modal) MarshalJSON

func (m Modal) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Modal) SubmitJSON

func (m Modal) SubmitJSON(b []byte, submitter Submitter) error

SubmitJSON submits a JSON byte slice to the modal form. This byte slice contains a JSON encoded bool in it, which is used to determine which button was clicked.

func (Modal) Title

func (m Modal) Title() string

Title returns the formatted title passed to the menu upon construction using NewModal().

func (Modal) WithBody

func (m Modal) WithBody(body ...any) Modal

WithBody creates a copy of the Modal form and changes its body to the body passed, after which the new Modal form is returned. The text is formatted following the rules of fmt.Sprintln.

func (Modal) WithButton1

func (m Modal) WithButton1(btn Button, onClick Handler) Modal

WithButton1 creates a copy of the Modal form and change the button 1 to the button passed.

func (Modal) WithButton2

func (m Modal) WithButton2(btn Button, onClick Handler) Modal

WithButton2 creates a copy of the Modal form and change the button 2 to the button passed.

type Slider

type Slider struct {
	// Text is the text displayed over the slider element. The text may contain Minecraft formatting codes.
	Text string
	// Min and Max are used to specify the minimum and maximum range of the slider. A value lower or higher
	// than these values cannot be selected.
	Min, Max float64
	// StepSize is the size that one step of the slider takes up. When set to 1.0 for example, a submitter
	// will be able to select only whole values.
	StepSize float64
	// Default is the default value filled out for the slider.
	Default float64
}

Slider represents a slider element. Submitters may move the slider to values within the range of the slider to select a value.

func NewSlider

func NewSlider(text string, min, max, stepSize, defaultValue float64) Slider

NewSlider creates and returns a new Slider using the values passed.

func (Slider) MarshalJSON

func (s Slider) MarshalJSON() ([]byte, error)

MarshalJSON ...

type StepSlider

type StepSlider Dropdown

StepSlider represents a slider that has a number of options that may be selected. It is essentially a combination of a Dropdown and a Slider, looking like a slider but having properties like a dropdown.

func NewStepSlider

func NewStepSlider(text string, options []string, defaultIndex int) StepSlider

NewStepSlider creates and returns new StepSlider using the values passed.

func (StepSlider) MarshalJSON

func (s StepSlider) MarshalJSON() ([]byte, error)

MarshalJSON ...

type Submitter

type Submitter interface {
	SendForm(form Form)
}

Submitter is an entity that is able to submit a form sent to it. It is able to fill out fields in the form which will then be present when handled.

type Toggle

type Toggle struct {
	// Text is the text displayed over the toggle element. The text may contain Minecraft formatting codes.
	Text string
	// Default is the default value filled out in the input. The user may remove this value and fill out its
	// own text. The text may contain Minecraft formatting codes.
	Default bool
}

Toggle represents an on-off button element. Submitters may either toggle this on or off, which will then hold a value of true or false respectively.

func NewToggle

func NewToggle(text string, defaultValue bool) Toggle

NewToggle creates and returns a new Toggle with the values passed.

func (Toggle) MarshalJSON

func (t Toggle) MarshalJSON() ([]byte, error)

MarshalJSON ...

Jump to

Keyboard shortcuts

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