From a166325465b70ccc34af953983f0b3da79eaa1d0 Mon Sep 17 00:00:00 2001 From: Cole Green <36878742-nox7@users.noreply.gitlab.com> Date: Fri, 1 May 2026 12:32:23 +0000 Subject: [PATCH] Add documentation of padding on base Widget --- components/lua_ui/textedit.cpp | 3 ++- components/lua_ui/widget.cpp | 15 +++++---------- .../reference/lua-scripting/widgets/widget.rst | 6 ++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/lua_ui/textedit.cpp b/components/lua_ui/textedit.cpp index 1342aa5186..e28f82a93d 100644 --- a/components/lua_ui/textedit.cpp +++ b/components/lua_ui/textedit.cpp @@ -76,7 +76,8 @@ namespace LuaUi std::max(0, normalSize.height - static_cast(mPadding.y() + mPadding.w()))); mEditBox->setSize(contentSize); int targetHeight = mMultiline ? mEditBox->getTextSize().height : mEditBox->getFontHeight(); - normalSize.height = std::max(normalSize.height, targetHeight + static_cast(mPadding.y() + mPadding.w())); + normalSize.height + = std::max(normalSize.height, targetHeight + static_cast(mPadding.y() + mPadding.w())); } return normalSize; } diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index 06847effbe..0c8c85a31b 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -346,11 +346,7 @@ namespace LuaUi bottom = table.get>(4); } - mPadding = osg::Vec4( - left.value_or(0.f), - top.value_or(0.f), - right.value_or(0.f), - bottom.value_or(0.f)); + mPadding = osg::Vec4(left.value_or(0.f), top.value_or(0.f), right.value_or(0.f), bottom.value_or(0.f)); } else if (padding != sol::nil) throw std::logic_error("Property \"padding\" must be either a number or a table"); @@ -379,12 +375,11 @@ namespace LuaUi return MyGUI::IntPoint(static_cast(mPadding.x()), static_cast(mPadding.y())); } - MyGUI::IntSize WidgetExtension::getContentSize() const { + MyGUI::IntSize WidgetExtension::getContentSize() const + { MyGUI::IntSize fullSize = calculateSize(); - return MyGUI::IntSize( - std::max(0, fullSize.width - static_cast(mPadding.x() + mPadding.z())), - std::max(0, fullSize.height - static_cast(mPadding.y() + mPadding.w())) - ); + return MyGUI::IntSize(std::max(0, fullSize.width - static_cast(mPadding.x() + mPadding.z())), + std::max(0, fullSize.height - static_cast(mPadding.y() + mPadding.w()))); } MyGUI::IntSize WidgetExtension::calculateSize() const diff --git a/docs/source/reference/lua-scripting/widgets/widget.rst b/docs/source/reference/lua-scripting/widgets/widget.rst index 38470e766f..c4fc0d0701 100644 --- a/docs/source/reference/lua-scripting/widgets/widget.rst +++ b/docs/source/reference/lua-scripting/widgets/widget.rst @@ -31,6 +31,12 @@ Properties - util.vector2 (0, 0) - | Offsets the widget's position by a fraction of its size. | Useful for centering or aligning to a corner. + * - padding + - number or table (default 0) + - | Adds inset spacing between the outer edge of the widget and its content. + - | When providing a number: the top, right, bottom, and right margins are all set + - | to that provided numebr. When providing a table, you can provide any of the padding directions + - | individually. Such as `{ top = 10, right = 5 }`. * - visible - boolean (true) - Defines if the widget is visible