From 84b2aef81f82d46b07d9bd059540d7ac90cae3ec Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 8 Jun 2026 22:21:15 +0300 Subject: [PATCH] fix ui elements related things --- res/modules/internal/gui_util.lua | 19 +++++++++++-------- res/modules/internal/test.lua | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/res/modules/internal/gui_util.lua b/res/modules/internal/gui_util.lua index 0ec47291e..656a0dfc8 100644 --- a/res/modules/internal/gui_util.lua +++ b/res/modules/internal/gui_util.lua @@ -77,15 +77,18 @@ function Element.new(docname, name) end -- the engine automatically creates an instance for every ui document (layout) -local Document = {} -function Document.new(docname) - return setmetatable({name=docname}, { - __index=function(self, k) - local elem = Element.new(self.name, k) - rawset(self, k, elem) - return elem +local Document = { + __index=function(self, k) + if type(k) ~= "string" then + error("element id is not a string") end - }) + local elem = Element.new(self.name, k) + rawset(self, k, elem) + return elem + end +} +function Document.new(docname) + return setmetatable({name=docname}, Document) end local RadioGroup = {} diff --git a/res/modules/internal/test.lua b/res/modules/internal/test.lua index a6ca7d096..ccabf3add 100644 --- a/res/modules/internal/test.lua +++ b/res/modules/internal/test.lua @@ -70,7 +70,7 @@ function test.click(node, options) end if not node.exists then error(string.format("timeout %s ms exceeded: element %s does not exists", - math.floor(timeout), string.escape(node.id))) + math.floor(timeout), string.escape(rawget(node, 'name')))) end local center_x, center_y = get_node_center(node) @@ -82,6 +82,9 @@ end -- TODO: replace with resolving in C++ side function test.find_by_attr(node, attr, value) + if getmetatable(node) == Document then + return test.find_by_attr(node.root, attr, value) + end if node[attr] == value then return node end