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 an 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 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.
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 New ¶
func New(submittable Submittable, title ...interface{}) Custom
New creates a new (custom) form with the title passed and returns it. The title is formatted according to the rules of fmt.Sprintln. The submittable passed is used to create the structure of the form. The values of the Submittable's form fields are used to set text, defaults and placeholders. If the Submittable passed is not a struct, New panics. New also panics if one of the exported field types of the Submittable is not one that implements the Element interface.
func (Custom) Elements ¶
Elements returns a list of all elements as set in the Submittable passed to form.New().
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 Submit() method of the form's Submittable is called and the fields of the Submittable will be filled out.
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 // contains filtered or unexported fields }
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.
type Element ¶
type Element interface {
// 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.New().
type Form ¶
type Form interface { 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 // contains filtered or unexported fields }
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
}
Menu represents a menu form. These menus are made up of a title and a body, with a number of buttons which come below the body. These buttons may also have buttons on the side of them.
func NewMenu ¶
func NewMenu(submittable MenuSubmittable, title ...interface{}) Menu
NewMenu creates a new Menu form using the MenuSubmittable passed to handle the output of the form. The title passed is formatted following the rules of fmt.Sprintln.
func (Menu) Buttons ¶
Buttons returns a list of all buttons of the MenuSubmittable. It parses them from the fields using reflection and returns them.
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().
func (Menu) WithBody ¶
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 (Menu) WithButtons ¶
WithButtons creates a copy of the Menu form and appends the buttons passed to the existing buttons, after which the new Menu form is returned.
type MenuSubmittable ¶
type MenuSubmittable interface { // Submit is called when the Submitter submits the menu form sent to it. The method is called with the // button that was pressed. It may be compared to buttons in the MenuSubmittable struct to check which // button was pressed. Submit(submitter Submitter, pressed Button) }
MenuSubmittable is a structure which may be submitted by sending it as a form using form.NewMenu(), much like a Submittable. The struct will have its Submit method called with the button pressed. A struct that implements the MenuSubmittable interface must only have exported fields with the type form.Button.
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 ¶
func NewModal(submittable ModalSubmittable, title ...interface{}) Modal
NewModal creates a new Modal form using the ModalSubmittable passed to handle the output of the form. The title passed is formatted following the fmt.Sprintln rules. Default 'yes' and 'no' buttons may be passed by setting the two exported struct fields of the submittable to YesButton() and NoButton() respectively.
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.
type ModalSubmittable ¶
type ModalSubmittable MenuSubmittable
ModalSubmittable is a structure which may be submitted by sending it as a form using form.NewModal(), much like a Submittable and a MenuSubmittable. The struct will have its Submit method called with the button pressed. A struct that implements the ModalSubmittable interface must have exactly two exported fields with the type form.Button, which may be used to specify the text of the Modal form's buttons. Unlike with a Menu form, buttons on a Modal form will not have images.
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 // contains filtered or unexported fields }
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 (StepSlider) Value ¶
func (s StepSlider) Value() int
Value returns the value that the Submitter submitted. The value is an index pointing to the selected option in the Options slice.
type Submittable ¶
type Submittable interface { // Submit is called when the Submitter submits the form sent to it. Once this method is called, all fields // in the struct will have their values filled out as filled out by the Submitter. Submit(submitter Submitter) }
Submittable is a structure which may be submitted by sending it as a form using form.New(). When filled out and submitted, the struct will have its Submit method called and its fields will have the values that the Submitter passed filled out. The fields of a Submittable struct must be either unexported or have a type of one of those that implement the form.Element interface.
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 // contains filtered or unexported fields }
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.