Documentation ¶
Index ¶
- type Button
- type Custom
- func (f Custom) Elements() []Element
- func (f Custom) MarshalJSON() ([]byte, error)
- func (f Custom) OnClose(c Handler) Custom
- func (f Custom) OnSubmit(c interface{}) Custom
- func (f Custom) SubmitJSON(b []byte, submitter Submitter) error
- func (f Custom) Title() string
- func (f Custom) WithElements(elem ...Element) Custom
- type Dropdown
- type Element
- type Form
- type Handler
- type Input
- type Label
- type Menu
- func (m Menu) Body() string
- func (m Menu) Buttons() []Button
- func (m Menu) MarshalJSON() ([]byte, error)
- func (m Menu) OnClose(onClose Handler) Menu
- func (m Menu) SubmitJSON(b []byte, submitter Submitter) error
- func (m Menu) Title() string
- func (m Menu) WithBody(body ...any) Menu
- func (m Menu) WithButton(btn Button, onClick Handler) Menu
- type Modal
- func (m Modal) Body() string
- func (m Modal) Buttons() []Button
- func (m Modal) MarshalJSON() ([]byte, error)
- func (m Modal) SubmitJSON(b []byte, submitter Submitter) error
- func (m Modal) Title() string
- func (m Modal) WithBody(body ...any) Modal
- func (m Modal) WithButton1(btn Button, onClick Handler) Modal
- func (m Modal) WithButton2(btn Button, onClick Handler) Modal
- type Slider
- type StepSlider
- type Submitter
- type Toggle
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 NoButton ¶
func NoButton() Button
NoButton returns a Button which may be used as a default 'no' button for a modal form.
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 ¶
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) OnClose ¶
OnClose creates a copy of the Menu form and set the form close callback to the passed one.
func (Custom) OnSubmit ¶
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 ¶
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 ¶
Title returns the formatted title passed when the form was created using NewCustom().
func (Custom) WithElements ¶
WithElements creates a copy of the Custom form and append the elements passed.
type Dropdown ¶
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 ¶
NewDropdown creates and returns new Dropdown using the values passed.
type Element ¶
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 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.
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.
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
func NewMenu ¶
NewMenu creates a new Menu form. The title passed is formatted following the rules of fmt.Sprintln.
func (Menu) Buttons ¶
Buttons returns a list of all buttons of the Menu. It is appended by calling WithButton.
func (Menu) OnClose ¶
OnClose creates a copy of the Menu form and set the form close callback to the passed one.
func (Menu) SubmitJSON ¶
SubmitJSON submits a JSON value to the menu, containing the index of the button clicked.
func (Menu) Title ¶
Title returns the formatted title passed to the menu upon construction using NewMenu().
type Modal ¶
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 ¶
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 ¶
Body returns the formatted text in the body passed to the menu using WithBody().
func (Modal) Buttons ¶
Buttons returns a list of all buttons of the Modal form, which will always be a total of two buttons.
func (Modal) SubmitJSON ¶
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 ¶
Title returns the formatted title passed to the menu upon construction using NewModal().
func (Modal) WithBody ¶
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 ¶
WithButton1 creates a copy of the Modal form and change the button 1 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.
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.
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.