From b3681fdbb0489d49333b3b5719fb79ddad504e95 Mon Sep 17 00:00:00 2001 From: Laurens Holst Date: Thu, 30 Apr 2020 22:47:00 +0200 Subject: [PATCH] [lua] Implement Dialog:modify for more properties Support modifying the following properties: Dialog:number { decimals } Dialog:slider { min, max, value } Dialog:combobox { option } Dialog:color { color } Dialog:shades { colors } Dialog:file { filename } --- src/app/script/dialog_class.cpp | 77 ++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/app/script/dialog_class.cpp b/src/app/script/dialog_class.cpp index 5e221fa82..47804d2ad 100644 --- a/src/app/script/dialog_class.cpp +++ b/src/app/script/dialog_class.cpp @@ -873,7 +873,82 @@ int Dialog_modify(lua_State* L) } lua_pop(L, 1); - // TODO slider value? combobox option(s)? color? colors (shade)?) + type = lua_getfield(L, 2, "decimals"); + if (type != LUA_TNIL) { + if (auto expr = dynamic_cast(widget)) { + expr->setDecimals(lua_tointegerx(L, -1, nullptr)); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "min"); + if (type != LUA_TNIL) { + if (auto slider = dynamic_cast(widget)) { + slider->setRange(lua_tointegerx(L, -1, nullptr), slider->getMaxValue()); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "max"); + if (type != LUA_TNIL) { + if (auto slider = dynamic_cast(widget)) { + slider->setRange(slider->getMinValue(), lua_tointegerx(L, -1, nullptr)); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "value"); + if (type != LUA_TNIL) { + if (auto slider = dynamic_cast(widget)) { + slider->setValue(lua_tointegerx(L, -1, nullptr)); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "option"); + if (auto p = lua_tostring(L, -1)) { + if (auto combobox = dynamic_cast(widget)) { + int index = combobox->findItemIndex(p); + if (index >= 0) + combobox->setSelectedItemIndex(index); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "color"); + if (type != LUA_TNIL) { + if (auto colorButton = dynamic_cast(widget)) { + colorButton->setColor(convert_args_into_color(L, -1)); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "colors"); + if (type != LUA_TNIL) { + if (auto colorShade = dynamic_cast(widget)) { + Shade shade; + if (lua_istable(L, -1)) { + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + app::Color color = convert_args_into_color(L, -1); + shade.push_back(color); + lua_pop(L, 1); + } + } + colorShade->setShade(shade); + } + } + lua_pop(L, 1); + + type = lua_getfield(L, 2, "filename"); + if (auto p = lua_tostring(L, -1)) { + if (auto filenameField = dynamic_cast(widget)) { + filenameField->setFilename(p); + } + } + lua_pop(L, 1); + + // TODO combobox options? shades mode? file title / open / save / filetypes? on* events? if (relayout) { dlg->window.layout();