From 1f5e3b78d4c0dcbeb4a9a6e0c5c8f36629120ba6 Mon Sep 17 00:00:00 2001 From: uramer Date: Thu, 7 Apr 2022 17:43:03 +0200 Subject: [PATCH] Use Flex, don't force re-renders on layout table changes --- components/lua_ui/element.cpp | 3 +-- components/lua_ui/flex.cpp | 1 + .../scripts/omw/settings/render.lua | 16 +++++++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/components/lua_ui/element.cpp b/components/lua_ui/element.cpp index 46eb543cca..9f70cfc1da 100644 --- a/components/lua_ui/element.cpp +++ b/components/lua_ui/element.cpp @@ -55,8 +55,7 @@ namespace LuaUi { WidgetExtension* ext = children[i]; sol::table newLayout = content.at(i); - if (ext->widget()->getTypeName() == widgetType(newLayout) - && ext->getLayout() == newLayout) + if (ext->widget()->getTypeName() == widgetType(newLayout)) { updateWidget(ext, newLayout); } diff --git a/components/lua_ui/flex.cpp b/components/lua_ui/flex.cpp index e90fba2a1a..dfe943a02f 100644 --- a/components/lua_ui/flex.cpp +++ b/components/lua_ui/flex.cpp @@ -71,6 +71,7 @@ namespace LuaUi w->forcePosition(childPosition); primary(size) += static_cast(growFactor * getGrow(w)); w->forceSize(size); + w->updateCoord(); primary(childPosition) += primary(size); w->updateCoord(); } diff --git a/files/builtin_scripts/scripts/omw/settings/render.lua b/files/builtin_scripts/scripts/omw/settings/render.lua index e77badcff7..0f9249a390 100644 --- a/files/builtin_scripts/scripts/omw/settings/render.lua +++ b/files/builtin_scripts/scripts/omw/settings/render.lua @@ -19,32 +19,30 @@ local function renderSetting(groupName, setting, value, index) local group = common.getGroup(groupName) group:set(setting.name, value) local element = groupOptions[groupName].element - element.layout.content[setting.name] = renderSetting(groupName, setting, value, index) + local settingLayout = renderSetting(groupName, setting, value, index) + settingLayout.name = setting.name + element.layout.content[setting.name] = settingLayout element:update() end) layout.name = setting.name - -- temporary hacky position and size - layout.props = layout.props or {} - layout.props.position = util.vector2(0, 100 * (index - 1)) - layout.props.size = util.vector2(400, 100) return layout end local function onGroupRegistered(groupName) local group = common.groups:get(groupName) local layout = { + type = ui.TYPE.Flex, content = ui.content{}, } local searchHints = { groupName } local count = 0 for _, setting in pairs(group) do count = count + 1 - layout.content:add(renderSetting(groupName, setting, setting.default, count)) + local settingLayout = renderSetting(groupName, setting, setting.default, count) + settingLayout.name = setting.name + layout.content:add(settingLayout) table.insert(searchHints, setting.name) end - layout.props = { - size = util.vector2(400, 100 * count) - } local options = { name = groupName, element = ui.create(layout),