Declarations
gui.Handler
| Zig |
|---|
| pub const Handler = fn (user: ?*anyopaque, response: Response) void;
|
What a handler receives: the user pointer given at send and the answer.
| Zig |
|---|
| pub const CustomForm = struct {
allocator: Allocator,
title: []const u8,
submit_text: ?[]const u8 = null,
elements: std.ArrayList(u8) = .empty,
// ...
};
|
A custom form: input fields, toggles, dropdowns and sliders, each named so the answer can be read by name. title is borrowed and must outlive the send.
| Zig |
|---|
| pub fn init(allocator: Allocator, title: []const u8) CustomForm
|
- Parameters:
- allocator :
Allocator
- title :
[]const u8
- Return type:
CustomForm
| Zig |
|---|
| pub fn deinit(self: *CustomForm) void
|
| Zig |
|---|
| pub fn setSubmit(self: *CustomForm, text: []const u8) void
|
The text of the submit button.
- Parameters:
- Return type:
void
| Zig |
|---|
| pub fn header(self: *CustomForm, text: []const u8) Allocator.Error!void
|
- Parameters:
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn label(self: *CustomForm, text: []const u8) Allocator.Error!void
|
- Parameters:
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn divider(self: *CustomForm) Allocator.Error!void
|
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn input(self: *CustomForm, name: []const u8, text: []const u8, placeholder: []const u8, default: []const u8) Allocator.Error!void
|
- Parameters:
- name :
[]const u8
- text :
[]const u8
- placeholder :
[]const u8
- default :
[]const u8
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn toggle(self: *CustomForm, name: []const u8, text: []const u8, default: bool) Allocator.Error!void
|
- Parameters:
- name :
[]const u8
- text :
[]const u8
- default :
bool
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn dropdown(self: *CustomForm, name: []const u8, text: []const u8, options: []const []const u8, default: usize) Allocator.Error!void
|
- Parameters:
- name :
[]const u8
- text :
[]const u8
- options :
[]const []const u8
- default :
usize
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn stepSlider(self: *CustomForm, name: []const u8, text: []const u8, steps: []const []const u8, default: usize) Allocator.Error!void
|
- Parameters:
- name :
[]const u8
- text :
[]const u8
- steps :
[]const []const u8
- default :
usize
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn slider(self: *CustomForm, name: []const u8, text: []const u8, min: f64, max: f64, step: f64, default: f64) Allocator.Error!void
|
- Parameters:
- name :
[]const u8
- text :
[]const u8
- min :
f64
- max :
f64
- step :
f64
- default :
f64
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn send(self: *const CustomForm, player: props.Player, user: ?*anyopaque, comptime handler: Handler) core.Error!void
|
- Parameters:
- player :
props.Player
- user :
?*anyopaque
- handler :
comptime Handler
- Return type:
core.Error!void
- Slots:
form_send
| Zig |
|---|
| pub const SimpleForm = struct {
allocator: Allocator,
title: []const u8,
content: []const u8 = "",
elements: std.ArrayList(u8) = .empty,
buttons: usize = 0,
// ...
};
|
A simple form: a column of buttons. title and content are borrowed and must outlive the send.
| Zig |
|---|
| pub fn init(allocator: Allocator, title: []const u8) SimpleForm
|
- Parameters:
- allocator :
Allocator
- title :
[]const u8
- Return type:
SimpleForm
| Zig |
|---|
| pub fn deinit(self: *SimpleForm) void
|
gui.SimpleForm.setContent
| Zig |
|---|
| pub fn setContent(self: *SimpleForm, content: []const u8) void
|
- Parameters:
- Return type:
void
| Zig |
|---|
| pub fn button(self: *SimpleForm, text: []const u8) Allocator.Error!void
|
- Parameters:
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn buttonWithImage(self: *SimpleForm, text: []const u8, image: []const u8, image_type: []const u8) Allocator.Error!void
|
A button with an icon. image_type is "path" or "url".
- Parameters:
- text :
[]const u8
- image :
[]const u8
- image_type :
[]const u8
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn header(self: *SimpleForm, text: []const u8) Allocator.Error!void
|
- Parameters:
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn label(self: *SimpleForm, text: []const u8) Allocator.Error!void
|
- Parameters:
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn divider(self: *SimpleForm) Allocator.Error!void
|
- Return type:
Allocator.Error!void
| Zig |
|---|
| pub fn send(self: *const SimpleForm, player: props.Player, user: ?*anyopaque, comptime handler: Handler) core.Error!void
|
Sends it. A form with no button at all is Refused, since a player cannot press it.
- Parameters:
- player :
props.Player
- user :
?*anyopaque
- handler :
comptime Handler
- Return type:
core.Error!void
- Slots:
form_send
| Zig |
|---|
| pub const FormValue = union(enum) {
index: usize,
number: f64,
text: []const u8,
boolean: bool,
// ...
};
|
The value one control of a custom form returns.
| Zig |
|---|
| pub fn asIndex(self: FormValue) ?usize
|
The chosen position of a dropdown or a step slider.
| Zig |
|---|
| pub fn asF64(self: FormValue) ?f64
|
| Zig |
|---|
| pub fn asI64(self: FormValue) ?i64
|
| Zig |
|---|
| pub fn asBool(self: FormValue) ?bool
|
gui.FormValue.asText
| Zig |
|---|
| pub fn asText(self: FormValue) ?[]const u8
|
gui.Response
| Zig |
|---|
| pub const Response = union(enum) {
/// The player closed the form; the reason is the engine's cancel code, or -1.
cancelled: i32,
/// The index of the button a simple form's player pressed.
button: usize,
/// Whether the player pressed the upper button of a modal form.
modal: bool,
custom: Custom,
/// An answer in a shape this binding does not know, as the host wrote it.
unknown: []const u8,
// ...
};
|
A player's answer to a form.
gui.Response.isCancelled
| Zig |
|---|
| pub fn isCancelled(self: Response) bool
|
gui.Response.value
| Zig |
|---|
| pub fn value(self: Response, name: []const u8) ?FormValue
|
The value of one control of a custom form.
- Parameters:
- Return type:
?FormValue
gui.Response.text
| Zig |
|---|
| pub fn text(self: Response, name: []const u8) ?[]const u8
|
The text of the selected item of one control of a custom form.
- Parameters:
- Return type:
?[]const u8
gui.Custom
| Zig |
|---|
| pub const Custom = struct {
entries: []const Entry,
// ...
};
|
The answers of a custom form, one entry per named control.
gui.Custom.value
| Zig |
|---|
| pub fn value(self: Custom, name: []const u8) ?FormValue
|
The value of one control.
- Parameters:
- Return type:
?FormValue
gui.Custom.text
| Zig |
|---|
| pub fn text(self: Custom, name: []const u8) ?[]const u8
|
The text of the selected item of one control.
- Parameters:
- Return type:
?[]const u8
| Zig |
|---|
| pub const ModalForm = struct {
allocator: Allocator,
title: []const u8,
content: []const u8,
upper: []const u8 = "OK",
lower: []const u8 = "Cancel",
// ...
};
|
A modal form: some text and two buttons. Every string is borrowed and must outlive the send.
| Zig |
|---|
| pub fn init(allocator: Allocator, title: []const u8, content: []const u8) ModalForm
|
- Parameters:
- allocator :
Allocator
- title :
[]const u8
- content :
[]const u8
- Return type:
ModalForm
| Zig |
|---|
| pub fn send(self: *const ModalForm, player: props.Player, user: ?*anyopaque, comptime handler: Handler) core.Error!void
|
- Parameters:
- player :
props.Player
- user :
?*anyopaque
- handler :
comptime Handler
- Return type:
core.Error!void
- Slots:
form_send
gui.Custom.Entry
| Zig |
|---|
| pub const Entry = struct {
name: []const u8,
value: FormValue,
/// The text of the selected item, for a control that has one.
text: ?[]const u8,
// ...
};
|