server.form
fn divider #
fn divider() Element
fn dropdown #
fn dropdown(text string, options []string, default_index int) Element
fn header #
fn header(text string) Element
fn input #
fn input(text string, default_value string, placeholder string) Element
fn label #
fn label(text string) Element
fn new_custom_form #
fn new_custom_form(title string, on_submit fn (Response) !) CustomForm
fn new_modal_form #
fn new_modal_form(title string, on_button1 fn () !, on_button2 fn () !) ModalForm
fn new_simple_form #
fn new_simple_form(title string) SimpleForm
fn slider #
fn slider(text string, min f64, max f64, step f64, default_value f64) Element
fn step_slider #
fn step_slider(text string, options []string, default_index int) Element
fn toggle #
fn toggle(text string, default_value bool) Element
interface Form #
interface Form {
// request_body returns the JSON payload sent to the client inside a ModalFormRequestPacket.
request_body() string
// submit is called with the raw form_data of the client's response.
// A `none` value means the player closed the form without submitting it.
submit(raw ?string) !
// has_network_image reports whether this form has a button image fetched
// over the network (type url), as opposed to a bundled resource pack
// asset (type path). The Bedrock client can get stuck showing a loading
// spinner on that image well after it has actually finished loading;
// assending the player an attribute update afterwards clears it. (see https://github.com/muqsit/FormImagesFix)
has_network_image() bool
}
type Element #
type Element = Divider | Dropdown | Header | Input | Label | Slider | StepSlider | Toggle
struct Button #
struct Button {
pub:
typ string = 'button' @[json: 'type']
text string
image ?ButtonImage
}
fn (Button) has_network_image #
fn (b Button) has_network_image() bool
struct ButtonImage #
struct ButtonImage {
pub:
typ string @[json: 'type']
data string
}
ButtonImage is the optional icon shown next to a Button on a SimpleForm or ModalForm. typ is path for a builtin game asset or url for a remote image.
struct CustomForm #
struct CustomForm {
mut:
title string
elements []Element
on_submit fn (Response) ! = unsafe { nil }
on_close ?fn ()
}
fn (CustomForm) element #
fn (mut f CustomForm) element(e Element) CustomForm
fn (CustomForm) closed #
fn (mut f CustomForm) closed(on_close fn ()) CustomForm
fn (CustomForm) request_body #
fn (f &CustomForm) request_body() string
fn (CustomForm) has_network_image #
fn (f &CustomForm) has_network_image() bool
has_network_image is always false because custom form elements don't carry images.
fn (CustomForm) submit #
fn (f &CustomForm) submit(raw ?string) !
struct Divider #
struct Divider {
pub:
typ string = 'divider' @[json: 'type']
text string
}
struct Dropdown #
struct Dropdown {
pub:
typ string = 'dropdown' @[json: 'type']
text string
options []string
default_index int @[json: 'default']
}
struct Header #
struct Header {
pub:
typ string = 'header' @[json: 'type']
text string
}
struct Input #
struct Input {
pub:
typ string = 'input' @[json: 'type']
text string
default string
placeholder string
}
struct Label #
struct Label {
pub:
typ string = 'label' @[json: 'type']
text string
}
struct ModalForm #
struct ModalForm {
mut:
title string
content string
button1 string = 'gui.yes'
button2 string = 'gui.no'
on_button1 fn () ! = unsafe { nil }
on_button2 fn () ! = unsafe { nil }
on_close ?fn ()
}
fn (ModalForm) body #
fn (mut f ModalForm) body(content string) ModalForm
fn (ModalForm) closed #
fn (mut f ModalForm) closed(on_close fn ()) ModalForm
fn (ModalForm) request_body #
fn (f &ModalForm) request_body() string
fn (ModalForm) has_network_image #
fn (f &ModalForm) has_network_image() bool
has_network_image is always false because modal form buttons don't carry images.
fn (ModalForm) submit #
fn (f &ModalForm) submit(raw ?string) !
struct Response #
struct Response {
values []json2.Any
}
fn (Response) len #
fn (r Response) len() int
fn (Response) string_value #
fn (r Response) string_value(index int) string
fn (Response) bool_value #
fn (r Response) bool_value(index int) bool
fn (Response) int_value #
fn (r Response) int_value(index int) int
fn (Response) f64_value #
fn (r Response) f64_value(index int) f64
struct SimpleForm #
struct SimpleForm {
mut:
title string
content string
buttons []Button
on_click []fn () !
on_close ?fn ()
}
fn (SimpleForm) body #
fn (mut f SimpleForm) body(content string) SimpleForm
fn (SimpleForm) closed #
fn (mut f SimpleForm) closed(on_close fn ()) SimpleForm
closed sets a callback invoked if the player closes the form without tapping a button.
fn (SimpleForm) request_body #
fn (f &SimpleForm) request_body() string
fn (SimpleForm) has_network_image #
fn (f &SimpleForm) has_network_image() bool
fn (SimpleForm) submit #
fn (f &SimpleForm) submit(raw ?string) !
struct Slider #
struct Slider {
pub:
typ string = 'slider' @[json: 'type']
text string
min f64
max f64
step f64
default f64
}
struct StepSlider #
struct StepSlider {
pub:
typ string = 'step_slider' @[json: 'type']
text string
options []string @[json: 'steps']
default_index int @[json: 'default']
}
struct Toggle #
struct Toggle {
pub:
typ string = 'toggle' @[json: 'type']
text string
default bool
}
- fn button
- fn divider
- fn dropdown
- fn header
- fn image_button
- fn input
- fn label
- fn new_custom_form
- fn new_modal_form
- fn new_simple_form
- fn slider
- fn step_slider
- fn toggle
- interface Form
- type Element
- struct Button
- struct ButtonImage
- struct CustomForm
- struct Divider
- struct Dropdown
- struct Header
- struct Input
- struct Label
- struct ModalForm
- struct Response
- struct SimpleForm
- struct Slider
- struct StepSlider
- struct Toggle