github.com/df-mc/dragonfly@v0.9.13/server/player/form/submit.go (about)

     1  package form
     2  
     3  // Submittable is a structure which may be submitted by sending it as a form using form.New(). When filled out
     4  // and submitted, the struct will have its Submit method called and its fields will have the values that the
     5  // Submitter passed filled out.
     6  // The fields of a Submittable struct must be either unexported or have a type of one of those that implement
     7  // the form.Element interface.
     8  type Submittable interface {
     9  	// Submit is called when the Submitter submits the form sent to it. Once this method is called, all fields
    10  	// in the struct will have their values filled out as filled out by the Submitter.
    11  	Submit(submitter Submitter)
    12  }
    13  
    14  // MenuSubmittable is a structure which may be submitted by sending it as a form using form.NewMenu(), much
    15  // like a Submittable. The struct will have its Submit method called with the button pressed.
    16  // A struct that implements the MenuSubmittable interface must only have exported fields with the type
    17  // form.Button.
    18  type MenuSubmittable interface {
    19  	// Submit is called when the Submitter submits the menu form sent to it. The method is called with the
    20  	// button that was pressed. It may be compared with buttons in the MenuSubmittable struct to check which
    21  	// button was pressed.
    22  	Submit(submitter Submitter, pressed Button)
    23  }
    24  
    25  // ModalSubmittable is a structure which may be submitted by sending it as a form using form.NewModal(), much
    26  // like a Submittable and a MenuSubmittable. The struct will have its Submit method called with the button
    27  // pressed.
    28  // A struct that implements the ModalSubmittable interface must have exactly two exported fields with the type
    29  // form.Button, which may be used to specify the text of the Modal form's buttons. Unlike with a Menu form,
    30  // buttons on a Modal form will not have images.
    31  type ModalSubmittable MenuSubmittable
    32  
    33  // Closer represents a form which has special logic when being closed by a Submitter.
    34  type Closer interface {
    35  	// Close is called when the Submitter closes a form.
    36  	Close(submitter Submitter)
    37  }
    38  
    39  // Submitter is an entity that is able to submit a form sent to it. It is able to fill out fields in the form
    40  // which will then be present when handled.
    41  type Submitter interface {
    42  	SendForm(form Form)
    43  }