From 727b953d6def596a354d98106fd75b2f315d352f Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sun, 13 Aug 2017 18:50:54 -0700 Subject: [PATCH] attempted #65, failed --- elements/element.lua | 8 ++++++++ elements/element.moon | 11 +++++++++++ main.lua | 2 ++ main.moon | 2 ++ 4 files changed, 23 insertions(+) diff --git a/elements/element.lua b/elements/element.lua index 274e255..d5cab19 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -1,3 +1,4 @@ +local pop local graphics graphics = love.graphics local floor, max @@ -11,6 +12,9 @@ local element do local _class_0 local _base_0 = { + load = function(pop_lib) + pop = pop_lib + end, align = function(self, horizontal, vertical, toPixel) if toPixel == nil then toPixel = true @@ -206,6 +210,10 @@ do return self end, delete = function(self) + if self == pop.hovered then + pop.hovered = false + pop.log(tostring(self) .. " (" .. tostring(self.type) .. ") unfocused (deleted)") + end for i = #self.child, 1, -1 do self.child[i]:delete() end diff --git a/elements/element.moon b/elements/element.moon index 12d11e7..357d93b 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -3,11 +3,16 @@ --- @copyright Paul Liverman III (2016) --- @license The MIT License (MIT) +local pop + import graphics from love import floor, max from math import inheritsFromElement from require "#{(...)\sub 1, -19}/util" class element + load: (pop_lib) -> + pop = pop_lib + --- Constructor expects nothing, or a data table describing it. --- @tparam ?Element|false parent The parent element. --- @tparam table data[opt] The data (state) for this element. @@ -253,6 +258,12 @@ class element --- Deletes references to this element and then deletes it. delete: => + -- does not work for desired issue, element is still referenced and set as focused after this would be called + -- however, it is probably a good idea for anything being deleted to make sure it isn't focused + if @ == pop.hovered + pop.hovered = false + pop.log "#{@} (#{@type}) unfocused (deleted)" + for i=#@child, 1, -1 @child[i]\delete! diff --git a/main.lua b/main.lua index 8de2c24..b938650 100644 --- a/main.lua +++ b/main.lua @@ -197,6 +197,8 @@ love.keypressed = function(key) return love.event.quit() elseif key == "d" then debug = not debug + elseif key == "t" then + return print("pop.focused", pop.focused) end end love.keyreleased = function(key) diff --git a/main.moon b/main.moon index d093109..eb937e6 100644 --- a/main.moon +++ b/main.moon @@ -80,6 +80,8 @@ love.keypressed = (key) -> love.event.quit! elseif key == "d" debug = not debug + elseif key == "t" + print("pop.focused", pop.focused) love.keyreleased = (key) -> pop.keyreleased key