Skip to content

Commit

Permalink
Add mutliplier newline_spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rob committed May 3, 2020
1 parent 33f3880 commit 31795a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2754,8 +2754,9 @@ Some types may inherit styles from parent types.
* `label`: Bottom of first line
* `vertlabel`: Bottom of first character
Default `centerline` for label and `top` for vertlabel.
* newline_spacing - number/`auto`, sets space in coordinates between lines/columns of text.
If set to `auto`, the text is as close together as possible without overlap. Default 0.5.
* 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
14 changes: 9 additions & 5 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,10 +1806,12 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)

std::string str_newline = style.get(StyleSpec::NEWLINE_SPACING, "0.5");
float newline_spacing;
if (trim(str_newline) == "auto")
newline_spacing = (float)font_height;
else
if (str_newline.size() > 0 && str_newline[0] == '*') {
str_newline = str_newline.substr(1);
newline_spacing = stof(str_newline) * (float)font_height;
} else {
newline_spacing = stof(str_newline) * (float)imgsize.Y;
}

s32 rect_height = abs(newline_spacing) * (float)(lines.size() - 1) + font_height;

Expand Down Expand Up @@ -1989,8 +1991,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen

std::string str_newline = style.get(StyleSpec::NEWLINE_SPACING, "0.5");
float newline_spacing = 0;
if (trim(str_newline) == "auto") {
newline_spacing = (float)font_width + m_font->getKerningWidth();
if (str_newline.size() > 0 && str_newline[0] == '*') {
str_newline = str_newline.substr(1);
newline_spacing = stof(str_newline) * (float)font_width +
m_font->getKerningWidth();
} else {
newline_spacing = stof(str_newline) * (float)imgsize.X;
}
Expand Down

0 comments on commit 31795a0

Please sign in to comment.