From 48e941cb2ff80256af4c7a00b62868f8f9e11c2c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 16 Apr 2020 11:48:44 -0300 Subject: [PATCH] [lua] Add Dialog:newrow{ always } --- src/app/script/dialog_class.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/script/dialog_class.cpp b/src/app/script/dialog_class.cpp index 6052e8054..8288511c4 100644 --- a/src/app/script/dialog_class.cpp +++ b/src/app/script/dialog_class.cpp @@ -51,6 +51,7 @@ struct Dialog { ui::VBox vbox; ui::Grid grid; ui::HBox* hbox = nullptr; + bool autoNewRow = false; std::map dataWidgets; std::map labelWidgets; int currentRadioGroup = 0; @@ -287,7 +288,8 @@ int Dialog_add_widget(lua_State* L, Widget* widget) // This is to separate different kind of widgets without label in // different rows. - if (dlg->lastWidgetType != widget->type()) { + if (dlg->lastWidgetType != widget->type() || + dlg->autoNewRow) { dlg->lastWidgetType = widget->type(); dlg->hbox = nullptr; } @@ -345,6 +347,20 @@ int Dialog_newrow(lua_State* L) { auto dlg = get_obj(L, 1); dlg->hbox = nullptr; + + dlg->autoNewRow = false; + if (lua_istable(L, 2)) { + // Dialog:newrow{ always } + const int type = lua_getfield(L, 2, "always"); + if (type != LUA_TNONE) { + if (type == LUA_TNIL || + lua_toboolean(L, -1)) { + dlg->autoNewRow = true; + } + lua_pop(L, 1); + } + } + lua_pushvalue(L, 1); return 1; }