Skip to content

Implement new form Elements #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions server/player/form/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,51 @@ func (Label) ReadOnly() bool {
return true
}

// Header represents a static header on a form. It serves only to display a large box of text, and users cannot
// submit values to it.
type Header struct {
// Text is the text held by the header. The text may contain Minecraft formatting codes.
Text string
}

// NewHeader creates and returns a new Header with the values passed.
func NewHeader(text string) Header {
return Header{Text: text}
}

// MarshalJSON ...
func (h Header) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"type": "header",
"text": h.Text,
})
}

func (Header) ReadOnly() bool {
return true
}

// Divider represents a static divider on a form. It serves only to display a section divider, and users cannot
// submit values to it.
type Divider struct{}

// NewDivider creates and returns a new Divider.
func NewDivider() Divider {
return Divider{}
}

// MarshalJSON ...
func (d Divider) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"type": "divider",
"text": "",
})
}

func (Divider) ReadOnly() bool {
return true
}

// Input represents a text input box element. Submitters may write any text in these boxes with no specific
// length.
type Input struct {
Expand Down Expand Up @@ -253,6 +298,8 @@ func (b Button) MarshalJSON() ([]byte, error) {
}

func (Label) elem() {}
func (Header) elem() {}
func (Divider) elem() {}
func (Input) elem() {}
func (Toggle) elem() {}
func (Slider) elem() {}
Expand Down