Skip to content

Commit

Permalink
restore compat
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Aug 31, 2024
1 parent 931c853 commit c743ed5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ local function get_formspec(dialogdata)
"tooltip[search;", fgettext("Search"), "]",
"tooltip[search_clear;", fgettext("Clear"), "]",
"container_end[]",
("scroll_container[0.25,1.25;%f,%f;leftscroll;vertical;0]"):format(
("scroll_container[0.25,1.25;%f,%f;leftscroll;vertical;0.1;0]"):format(
left_pane_width, tabsize.height - 1.5),
"style_type[button;border=false;bgcolor=#3333]",
"style_type[button:hover;border=false;bgcolor=#6663]",
Expand Down Expand Up @@ -536,7 +536,7 @@ local function get_formspec(dialogdata)
end

local right_pane_width = tabsize.width - left_pane_width - 0.375 - 2*scrollbar_w - 0.25
fs[#fs + 1] = ("scroll_container[%f,0;%f,%f;rightscroll;vertical;0.25]"):format(
fs[#fs + 1] = ("scroll_container[%f,0;%f,%f;rightscroll;vertical;0.1;0.25]"):format(
tabsize.width - right_pane_width - scrollbar_w, right_pane_width, tabsize.height)

y = 0.25
Expand Down
6 changes: 4 additions & 2 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,8 @@ Version History
* Formspec version 7 (5.8.0):
* style[]: Add focused state for buttons
* Add field_enter_after_edit[] (experimental)
* Formspec version 8 (5.9.0)
* Formspec version 8 (5.10.0)
* scoll_container[]: content padding parameter

Elements
--------
Expand Down Expand Up @@ -2764,14 +2765,15 @@ Elements
* End of a container, following elements are no longer relative to this
container.

### `scroll_container[<X>,<Y>;<W>,<H>;<scrollbar name>;<orientation>;<content padding>]`
### `scroll_container[<X>,<Y>;<W>,<H>;<scrollbar name>;<orientation>;<scroll factor>;<content padding>]`

* Start of a scroll_container block. All contained elements will ...
* take the scroll_container coordinate as position origin,
* be additionally moved by the current value of the scrollbar with the name
`scrollbar name` times `scroll factor` along the orientation `orientation` and
* be clipped to the rectangle defined by `X`, `Y`, `W` and `H`.
* `orientation`: possible values are `vertical` and `horizontal`.
* `scroll factor`: optional, defaults to `0.1`.
* `content padding`: (optional), in formspec units
* If specified, the scrollbar properties `max` and `thumbsize` are calculated automatically
based on the content size plus `content padding` at the end of the container.
Expand Down
10 changes: 6 additions & 4 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,20 @@ void GUIFormSpecMenu::parseContainerEnd(parserData* data, const std::string &)
void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &element)
{
std::vector<std::string> parts;
if (!precheckElement("scroll_container start", element, 4, 5, parts))
if (!precheckElement("scroll_container start", element, 4, 6, parts))
return;

std::vector<std::string> v_pos = split(parts[0], ',');
std::vector<std::string> v_geom = split(parts[1], ',');
std::string scrollbar_name = parts[2];
std::string orientation = parts[3];
f32 scroll_factor = 0.1f;
if (parts.size() >= 5 && !parts[4].empty())
scroll_factor = stof(parts[4]);

std::optional<s32> content_padding_px;
if (parts.size() >= 5 && !parts[4].empty()) {
std::vector<std::string> v_size = { parts[4], "0" };
if (parts.size() >= 6 && !parts[5].empty()) {
std::vector<std::string> v_size = { parts[5], "0" };
content_padding_px = getRealCoordinateGeometry(v_size)[0];
}

Expand All @@ -375,7 +378,6 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &
v2s32 pos = getRealCoordinateBasePos(v_pos);
v2s32 geom = getRealCoordinateGeometry(v_geom);

f32 scroll_factor = 0.1f;
if (orientation == "vertical")
scroll_factor *= -imgsize.Y;
else if (orientation == "horizontal")
Expand Down

0 comments on commit c743ed5

Please sign in to comment.