From 5e7004e7af71fa7f2f980414c9951a93c0a0e994 Mon Sep 17 00:00:00 2001 From: v-rob <31123645+v-rob@users.noreply.github.com> Date: Thu, 27 Jun 2019 05:40:49 -0700 Subject: [PATCH] Add compatible, consistent coordinate system to FormSpecs. (#8524) --- doc/lua_api.txt | 132 ++++++++- src/gui/guiFormSpecMenu.cpp | 553 ++++++++++++++++++++++++++---------- src/gui/guiFormSpecMenu.h | 11 +- 3 files changed, 542 insertions(+), 154 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 155da14e3..d881c4ef1 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1875,9 +1875,15 @@ is used when the server receives user input. You must not use the name Spaces and newlines can be inserted between the blocks, as is used in the examples. -Position and size units are inventory slots, `X` and `Y` position the formspec -element relative to the top left of the menu or container. `W` and `H` are its -width and height values. +Position and size units are inventory slots unless the new coordinate system +is enabled. `X` and `Y` position the formspec element relative to the top left +of the menu or container. `W` and `H` are its width and height values. + +If the new system is enabled, all elements have unified coordinates for all +elements with no padding or spacing in between. This is highly recommended +for new forms. See `real_coordinates[]` and `Migrating to Real +Coordinates`. + Inventories with a `player:` inventory location are only sent to the player named ``. @@ -1951,6 +1957,16 @@ Elements * Must be used after the `size`, `position`, and `anchor` elements (if present). * Disables player:set_formspec_prepend() from applying to this formspec. +### `real_coordinates[]` + +* When set to true, all following formspec elements will use the new coordinate system. +* If used immediately after `size`, `position`, `anchor`, and `no_prepend` elements + (if present), the form size will use the new coordinate system. +* **Note**: Formspec prepends are not affected by the coordinates in the main form. + They must enable it explicitly. +* For information on converting forms to the new coordinate system, see `Migrating + to Real Coordinates`. + ### `container[,]` * Start of a container block, moves all physical elements in the container by @@ -1968,11 +1984,15 @@ Elements * Show an inventory list if it has been sent to the client. Nothing will be shown if the inventory list is of size 0. +* **Note**: With the new coordinate system, the spacing between inventory + slots is one-fourth the size of an inventory slot. ### `list[;;,;,;]` * Show an inventory list if it has been sent to the client. Nothing will be shown if the inventory list is of size 0. +* **Note**: With the new coordinate system, the spacing between inventory + slots is one-fourth the size of an inventory slot. ### `listring[;]` @@ -2064,7 +2084,8 @@ Elements * Textual password style field; will be sent to server when a button is clicked * When enter is pressed in field, fields.key_enter_field will be sent with the name of this field. -* Fields are a set height, but will be vertically centred on `H` +* With the old coordinate system, fields are a set height, but will be vertically + centred on `H`. With the new coordinate system, `H` will modify the height. * `name` is the name of the field as returned in fields to `on_receive_fields` * `label`, if not blank, will be text printed on the top left above the field * See `field_close_on_enter` to stop enter closing the formspec @@ -2074,7 +2095,8 @@ Elements * Textual field; will be sent to server when a button is clicked * When enter is pressed in field, `fields.key_enter_field` will be sent with the name of this field. -* Fields are a set height, but will be vertically centred on `H` +* With the old coordinate system, fields are a set height, but will be vertically + centred on `H`. With the new coordinate system, `H` will modify the height. * `name` is the name of the field as returned in fields to `on_receive_fields` * `label`, if not blank, will be text printed on the top left above the field * `default` is the default value of the field @@ -2111,23 +2133,34 @@ Elements * The label formspec element displays the text set in `label` at the specified position. +* **Note**: If the new coordinate system is enabled, labels are + positioned from the center of the text, not the top. * The text is displayed directly without automatic line breaking, - so label should not be used for big text chunks. + so label should not be used for big text chunks. Newlines can be + used to make labels multiline. +* **Note**: With the new coordinate system, newlines are spaced with + half a coordinate. With the old system, newlines are spaced 2/5 of + an inventory slot. ### `vertlabel[,;