Lua: Add Splitter arguments

Change-Id: I51c33621bc424a65ae5aa14dd8340534477e96f3
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-08-20 10:26:03 +02:00
parent 157af836fd
commit f1c7e42aa3
2 changed files with 38 additions and 5 deletions

View File

@@ -245,6 +245,18 @@ std::unique_ptr<Splitter> constructSplitter(const sol::table &children)
std::unique_ptr<Splitter> item(new Splitter({}));
constructWidget(item, children);
if (const auto &orientation = children.get<sol::optional<QString>>("orientation")) {
if (*orientation == "horizontal")
item->setOrientation(Qt::Horizontal);
else if (*orientation == "vertical")
item->setOrientation(Qt::Vertical);
else
throw sol::error(QString("Invalid orientation: %1").arg(*orientation).toStdString());
}
if (const auto collapsible = children.get<sol::optional<bool>>("collapsible"))
item->setChildrenCollapsible(*collapsible);
for (size_t i = 1; i <= children.size(); ++i) {
const auto &child = children[i];
if (child.is<Layout *>()) {
@@ -256,6 +268,14 @@ std::unique_ptr<Splitter> constructSplitter(const sol::table &children)
<< " (expected Layout or Widget)";
}
}
if (const auto &stretchFactors = children.get<sol::optional<sol::table>>("stretchFactors")) {
for (const auto &kv : *stretchFactors) {
if (kv.second.get_type() != sol::type::number)
throw sol::error("Stretch factors must be numbers");
item->setStretchFactor(kv.first.as<int>() - 1, kv.second.as<int>());
}
}
return item;
}

View File

@@ -17,14 +17,17 @@ gui.widget = {}
---@alias LayoutChild string|BaseAspect|Layout|Widget|function
---@alias LayoutChildren LayoutChild[]
---@class (exact) WidgetOptions
---@class (exact) BaseWidgetOptions
---@field size? integer[] Two integers, representing the width and height of the widget.
---@field windowFlags? WindowType[] The window flags of the widget.
gui.baseWidgetOptions = {}
---@class (exact) WidgetOptions : BaseWidgetOptions
---@field title? string The title of the widget, if applicable.
---@field onTextChanged? function The function to be called when the text of the widget changes, if applicable.
---@field onClicked? function The function to be called when the widget is clicked, if applicable.
---@field text? string The text of the widget, if applicable.
---@field title? string The title of the widget, if applicable.
---@field value? integer The value of the widget, if applicable.
---@field size? integer[] Two integers, representing the width and height of the widget.
---@field windowFlags? WindowType[] The window flags of the widget.
---@field [1]? Layout The layout of the widget, if applicable.
gui.widgetOptions = {}
@@ -144,7 +147,17 @@ function gui.SpinBox(options) end
---@class Splitter : Widget
local splitter = {}
---@param options WidgetOptions
---@alias Orientation "horizontal"|"vertical"
---@class (exact) SplitterOptions : BaseWidgetOptions
---@field orientation? Orientation The orientation of the splitter. (default: "vertical")
---@field childrenCollapsible? boolean A boolean, representing whether the children are collapsible. (default: true)
---@field stretchFactors? integer[] A list of integers, representing the stretch factors of the children. (default: {1, ...})
---@field size? integer[] Two integers, representing the width and height of the widget.
---@field [integer] Layout | Widget The splits.
gui.splitterOptions = {}
---@param options SplitterOptions
---@return Splitter
function gui.Splitter(options) end