From f4f36b020b6d1ea2bba9962947ef9fc0d36320f7 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 28 Jul 2022 10:15:12 -0400 Subject: [PATCH] #84 recursive get element by id --- graphics/element.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/graphics/element.lua b/graphics/element.lua index 64e1029..40b3f66 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -187,8 +187,20 @@ function element.new(args) ---@param key string|integer function public.remove(key) self.children[key] = nil end + -- attempt to get a child element by ID (does not include this element itself) ---@param id element_id + ---@return graphics_element|nil element function public.get_element_by_id(id) + if self.children[id] == nil then + for _, child in pairs(self.children) do + local elem = child.get_element_by_id(id) + if elem ~= nil then return elem end + end + else + return self.children[id] + end + + return nil end -- get the foreground/background colors