@@ -1875,9 +1875,15 @@ is used when the server receives user input. You must not use the name
1875
1875
Spaces and newlines can be inserted between the blocks, as is used in the
1876
1876
examples.
1877
1877
1878
- Position and size units are inventory slots, `X` and `Y` position the formspec
1879
- element relative to the top left of the menu or container. `W` and `H` are its
1880
- width and height values.
1878
+ Position and size units are inventory slots unless the new coordinate system
1879
+ is enabled. `X` and `Y` position the formspec element relative to the top left
1880
+ of the menu or container. `W` and `H` are its width and height values.
1881
+
1882
+ If the new system is enabled, all elements have unified coordinates for all
1883
+ elements with no padding or spacing in between. This is highly recommended
1884
+ for new forms. See `real_coordinates[<bool>]` and `Migrating to Real
1885
+ Coordinates`.
1886
+
1881
1887
Inventories with a `player:<name>` inventory location are only sent to the
1882
1888
player named `<name>`.
1883
1889
@@ -1951,6 +1957,16 @@ Elements
1951
1957
* Must be used after the `size`, `position`, and `anchor` elements (if present).
1952
1958
* Disables player:set_formspec_prepend() from applying to this formspec.
1953
1959
1960
+ ### `real_coordinates[<bool>]`
1961
+
1962
+ * When set to true, all following formspec elements will use the new coordinate system.
1963
+ * If used immediately after `size`, `position`, `anchor`, and `no_prepend` elements
1964
+ (if present), the form size will use the new coordinate system.
1965
+ * **Note**: Formspec prepends are not affected by the coordinates in the main form.
1966
+ They must enable it explicitly.
1967
+ * For information on converting forms to the new coordinate system, see `Migrating
1968
+ to Real Coordinates`.
1969
+
1954
1970
### `container[<X>,<Y>]`
1955
1971
1956
1972
* Start of a container block, moves all physical elements in the container by
@@ -1968,11 +1984,15 @@ Elements
1968
1984
1969
1985
* Show an inventory list if it has been sent to the client. Nothing will
1970
1986
be shown if the inventory list is of size 0.
1987
+ * **Note**: With the new coordinate system, the spacing between inventory
1988
+ slots is one-fourth the size of an inventory slot.
1971
1989
1972
1990
### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
1973
1991
1974
1992
* Show an inventory list if it has been sent to the client. Nothing will
1975
1993
be shown if the inventory list is of size 0.
1994
+ * **Note**: With the new coordinate system, the spacing between inventory
1995
+ slots is one-fourth the size of an inventory slot.
1976
1996
1977
1997
### `listring[<inventory location>;<list name>]`
1978
1998
@@ -2064,7 +2084,8 @@ Elements
2064
2084
* Textual password style field; will be sent to server when a button is clicked
2065
2085
* When enter is pressed in field, fields.key_enter_field will be sent with the
2066
2086
name of this field.
2067
- * Fields are a set height, but will be vertically centred on `H`
2087
+ * With the old coordinate system, fields are a set height, but will be vertically
2088
+ centred on `H`. With the new coordinate system, `H` will modify the height.
2068
2089
* `name` is the name of the field as returned in fields to `on_receive_fields`
2069
2090
* `label`, if not blank, will be text printed on the top left above the field
2070
2091
* See `field_close_on_enter` to stop enter closing the formspec
@@ -2074,7 +2095,8 @@ Elements
2074
2095
* Textual field; will be sent to server when a button is clicked
2075
2096
* When enter is pressed in field, `fields.key_enter_field` will be sent with
2076
2097
the name of this field.
2077
- * Fields are a set height, but will be vertically centred on `H`
2098
+ * With the old coordinate system, fields are a set height, but will be vertically
2099
+ centred on `H`. With the new coordinate system, `H` will modify the height.
2078
2100
* `name` is the name of the field as returned in fields to `on_receive_fields`
2079
2101
* `label`, if not blank, will be text printed on the top left above the field
2080
2102
* `default` is the default value of the field
@@ -2111,23 +2133,34 @@ Elements
2111
2133
2112
2134
* The label formspec element displays the text set in `label`
2113
2135
at the specified position.
2136
+ * **Note**: If the new coordinate system is enabled, labels are
2137
+ positioned from the center of the text, not the top.
2114
2138
* The text is displayed directly without automatic line breaking,
2115
- so label should not be used for big text chunks.
2139
+ so label should not be used for big text chunks. Newlines can be
2140
+ used to make labels multiline.
2141
+ * **Note**: With the new coordinate system, newlines are spaced with
2142
+ half a coordinate. With the old system, newlines are spaced 2/5 of
2143
+ an inventory slot.
2116
2144
2117
2145
### `vertlabel[<X>,<Y>;<label>]`
2118
2146
2119
2147
* Textual label drawn vertically
2120
2148
* `label` is the text on the label
2149
+ * **Note**: If the new coordinate system is enabled, vertlabels are
2150
+ positioned from the center of the text, not the left.
2121
2151
2122
2152
### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`
2123
2153
2124
2154
* Clickable button. When clicked, fields will be sent.
2125
- * Fixed button height. It will be vertically centred on `H`
2155
+ * With the old coordinate system, buttons are a set height, but will be vertically
2156
+ centred on `H`. With the new coordinate system, `H` will modify the height.
2126
2157
* `label` is the text on the button
2127
2158
2128
2159
### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
2129
2160
2130
2161
* `texture name` is the filename of an image
2162
+ * **Note**: Height is supported on both the old and new coordinate systems
2163
+ for image_buttons.
2131
2164
2132
2165
### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]`
2133
2166
@@ -2146,10 +2179,12 @@ Elements
2146
2179
### `button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]`
2147
2180
2148
2181
* When clicked, fields will be sent and the form will quit.
2182
+ * Same as `button` in all other respects.
2149
2183
2150
2184
### `image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
2151
2185
2152
2186
* When clicked, fields will be sent and the form will quit.
2187
+ * Same as `image_button` in all other respects.
2153
2188
2154
2189
### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]`
2155
2190
@@ -2175,6 +2210,34 @@ Elements
2175
2210
### `tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
2176
2211
2177
2212
* Show a tab**header** at specific position (ignores formsize)
2213
+ * `X` and `Y`: position of the tabheader
2214
+ * *Note*: Width and height are automatically chosen with this syntax
2215
+ * `name` fieldname data is transferred to Lua
2216
+ * `caption 1`...: name shown on top of tab
2217
+ * `current_tab`: index of selected tab 1...
2218
+ * `transparent` (optional): show transparent
2219
+ * `draw_border` (optional): draw border
2220
+
2221
+ ### `tabheader[<X>,<Y>;<H>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
2222
+
2223
+ * Show a tab**header** at specific position (ignores formsize)
2224
+ * **Important note**: This syntax for tabheaders can only be used with the
2225
+ new coordinate system.
2226
+ * `X` and `Y`: position of the tabheader
2227
+ * `H`: height of the tabheader. Width is automatically determined with this syntax.
2228
+ * `name` fieldname data is transferred to Lua
2229
+ * `caption 1`...: name shown on top of tab
2230
+ * `current_tab`: index of selected tab 1...
2231
+ * `transparent` (optional): show transparent
2232
+ * `draw_border` (optional): draw border
2233
+
2234
+ ### `tabheader[<X>,<Y>;<W>,<H>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
2235
+
2236
+ * Show a tab**header** at specific position (ignores formsize)
2237
+ * **Important note**: This syntax for tabheaders can only be used with the
2238
+ new coordinate system.
2239
+ * `X` and `Y`: position of the tabheader
2240
+ * `W` and `H`: width and height of the tabheader
2178
2241
* `name` fieldname data is transferred to Lua
2179
2242
* `caption 1`...: name shown on top of tab
2180
2243
* `current_tab`: index of selected tab 1...
@@ -2193,8 +2256,22 @@ Elements
2193
2256
* **Important note**: There are two different operation modes:
2194
2257
1. handle directly on change (only changed dropdown is submitted)
2195
2258
2. read the value on pressing a button (all dropdown values are available)
2196
- * `x` and `y` position of dropdown
2197
- * Width of dropdown
2259
+ * `X` and `Y`: position of the dropdown
2260
+ * `W`: width of the dropdown. Height is automatically chosen with this syntax.
2261
+ * Fieldname data is transferred to Lua
2262
+ * Items to be shown in dropdown
2263
+ * Index of currently selected dropdown item
2264
+
2265
+ ### `dropdown[<X>,<Y>;<W>,<H>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
2266
+
2267
+ * Show a dropdown field
2268
+ * **Important note**: This syntax for dropdowns can only be used with the
2269
+ new coordinate system.
2270
+ * **Important note**: There are two different operation modes:
2271
+ 1. handle directly on change (only changed dropdown is submitted)
2272
+ 2. read the value on pressing a button (all dropdown values are available)
2273
+ * `X` and `Y`: position of the dropdown
2274
+ * `W` and `H`: width and height of the dropdown
2198
2275
* Fieldname data is transferred to Lua
2199
2276
* Items to be shown in dropdown
2200
2277
* Index of currently selected dropdown item
@@ -2205,6 +2282,8 @@ Elements
2205
2282
* `name` fieldname data is transferred to Lua
2206
2283
* `label` to be shown left of checkbox
2207
2284
* `selected` (optional): `true`/`false`
2285
+ * **Note**: If the new coordinate system is enabled, checkboxes are
2286
+ positioned from the center of the checkbox, not the top.
2208
2287
2209
2288
### `scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]`
2210
2289
@@ -2281,6 +2360,41 @@ Elements
2281
2360
**Note**: do _not_ use a element name starting with `key_`; those names are
2282
2361
reserved to pass key press events to formspec!
2283
2362
2363
+ Migrating to Real Coordinates
2364
+ -----------------------------
2365
+
2366
+ In the old system, positions included padding and spacing. Padding is a gap between
2367
+ the formspec window edges and content, and spacing is the gaps between items. For
2368
+ example, two `1x1` elements at `0,0` and `1,1` would have a spacing of `5/4` between them,
2369
+ and a padding of `3/8` from the formspec edge. It may be easiest to recreate old layouts
2370
+ in the new coordinate system from scratch.
2371
+
2372
+ To recreate an old layout with padding, you'll need to pass the positions and sizes
2373
+ through the following formula to re-introduce padding:
2374
+
2375
+ ```
2376
+ pos = (oldpos + 1)*spacing + padding
2377
+ where
2378
+ padding = 3/8
2379
+ spacing = 5/4
2380
+ ```
2381
+
2382
+ You'll need to change the `size[]` tag like this:
2383
+
2384
+ ```
2385
+ size = (oldsize-1)*spacing + padding*2 + 1
2386
+ ```
2387
+
2388
+ A few elements had random offsets in the old system. Here is a table which shows these
2389
+ offsets when migrating:
2390
+
2391
+ | Element | Position | Size | Notes
2392
+ |---------|------------|---------|-------
2393
+ | box | +0.3, +0.1 | 0, -0.4 |
2394
+ | button | | | Buttons now support height, so set h = 2 * 15/13 * 0.35, and reposition if h ~= 15/13 * 0.35 before
2395
+ | list | | | Spacing is now 0.25 for both directions, meaning lists will be taller in height
2396
+ | label | 0, +0.3 | | The first line of text is now positioned centered exactly at the position specified
2397
+
2284
2398
2285
2399
2286
2400
0 commit comments