Skip to content
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

Add origin options to FormSpec labels #8658

Closed
wants to merge 12 commits into from
32 changes: 26 additions & 6 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2310,12 +2310,12 @@ 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.
positioned from the center of the text by default, not the top.
* The text is displayed directly without automatic line breaking,
so label should not be used for big text chunks. Newlines can be
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
* **Note**: With the new coordinate system, newlines are defaultly spaced
with half a coordinate. With the old system, newlines are spaced 2/5 of
an inventory slot.

### `hypertext[<X>,<Y>;<W>,<H>;<name>;<text>]`
Expand All @@ -2328,8 +2328,9 @@ Elements
### `vertlabel[<X>,<Y>;<label>]`
* Textual label drawn vertically
* `label` is the text on the label
* **Note**: If the new coordinate system is enabled, vertlabels are
positioned from the center of the text, not the left.
* **Note**: If the new coordinate system is enabled, vertlabels are positioned
from the center of the text by default, not the left.
* Newlines in a vertlabel add columns to the right of the starting text.

### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`

Expand Down Expand Up @@ -2725,6 +2726,25 @@ Some types may inherit styles from parent types.
* noclip - boolean, set to true to allow the element to exceed formspec bounds. Default to false.
* label, vertlabel
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
* horigin - Sets horizontal origin in relation to label text. Possible values:
* `left`: Left side of the bounding box
* `center`: Center of the bounding box
* `right`: Right side of the bounding box
* `leftline` (vertlabel only): Left end of first column
* `centerline` (vertlabel only): Center of first column
* `rightline` (vertlabel only): Right end of first column
Default `left` for label and `centerline` for vertlabel.
* vorigin - Sets vertical origin in relation to label text. Possible values:
* `top`: Top of the bounding box
* `center`: Center of the bounding box
* `bottom`: Bottom of the bounding box
* `topline` (label only): Top of first line
* `centerline` (label only): Center of first line
* `bottomline` (label only): Bottom of first line
Default `centerline` for label and `top` for vertlabel.
* newline_spacing - number, sets space between lines/columns of text. If
the number is prefixed with `*`, the spacing is set to a multiple of the
label's font height or width, otherwise it's in coordinates. Default `0.5`.
* image_button (additional properties)
* fgimg - standard image. Defaults to none.
* fgimg_hovered - image when hovered. Defaults to fgimg when not provided.
Expand Down
9 changes: 9 additions & 0 deletions src/gui/StyleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class StyleSpec
ALPHA,
CONTENT_OFFSET,
PADDING,
HORIGIN,
VORIGIN,
NEWLINE_SPACING,
NUM_PROPERTIES,
NONE
};
Expand Down Expand Up @@ -98,6 +101,12 @@ class StyleSpec
return CONTENT_OFFSET;
} else if (name == "padding") {
return PADDING;
} else if (name == "horigin") {
return HORIGIN;
} else if (name == "vorigin") {
return VORIGIN;
} else if (name == "newline_spacing") {
return NEWLINE_SPACING;
} else {
return NONE;
}
Expand Down
Loading