forked from qt-creator/qt-creator
Lua: Add Splitter arguments
Change-Id: I51c33621bc424a65ae5aa14dd8340534477e96f3 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -245,6 +245,18 @@ std::unique_ptr<Splitter> constructSplitter(const sol::table &children)
|
|||||||
std::unique_ptr<Splitter> item(new Splitter({}));
|
std::unique_ptr<Splitter> item(new Splitter({}));
|
||||||
constructWidget(item, children);
|
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) {
|
for (size_t i = 1; i <= children.size(); ++i) {
|
||||||
const auto &child = children[i];
|
const auto &child = children[i];
|
||||||
if (child.is<Layout *>()) {
|
if (child.is<Layout *>()) {
|
||||||
@@ -256,6 +268,14 @@ std::unique_ptr<Splitter> constructSplitter(const sol::table &children)
|
|||||||
<< " (expected Layout or Widget)";
|
<< " (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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,14 +17,17 @@ gui.widget = {}
|
|||||||
---@alias LayoutChild string|BaseAspect|Layout|Widget|function
|
---@alias LayoutChild string|BaseAspect|Layout|Widget|function
|
||||||
---@alias LayoutChildren LayoutChild[]
|
---@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 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 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 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 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.
|
---@field [1]? Layout The layout of the widget, if applicable.
|
||||||
gui.widgetOptions = {}
|
gui.widgetOptions = {}
|
||||||
|
|
||||||
@@ -144,7 +147,17 @@ function gui.SpinBox(options) end
|
|||||||
---@class Splitter : Widget
|
---@class Splitter : Widget
|
||||||
local splitter = {}
|
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
|
---@return Splitter
|
||||||
function gui.Splitter(options) end
|
function gui.Splitter(options) end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user