1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

scrollcontainer: Add automatic scrollbar calculation (#14623)

New parameter 'content padding'. When specified, the scrollbar
max value is calculated automatically. This aims to reduce manual
calculation functions.
This commit is contained in:
SmallJoker 2024-10-08 21:45:27 +02:00 committed by GitHub
parent 291c3ad0c1
commit 13f533d490
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 87 additions and 29 deletions

View file

@ -356,7 +356,7 @@ 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], ',');
@ -367,6 +367,12 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &
if (parts.size() >= 5 && !parts[4].empty())
scroll_factor = stof(parts[4]);
std::optional<s32> content_padding_px;
if (parts.size() >= 6 && !parts[5].empty()) {
std::vector<std::string> v_size = { parts[5], parts[5] };
content_padding_px = getRealCoordinateGeometry(v_size)[orientation == "vertical" ? 1 : 0];
}
MY_CHECKPOS("scroll_container", 0);
MY_CHECKGEOM("scroll_container", 1);
@ -405,6 +411,7 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &
GUIScrollContainer *mover = new GUIScrollContainer(Environment,
clipper, spec_mover.fid, rect_mover, orientation, scroll_factor);
mover->setContentPadding(content_padding_px);
data->current_parent = mover;