diff --git a/elements/window.lua b/elements/window.lua index 7b05f29..1cacc5e 100644 --- a/elements/window.lua +++ b/elements/window.lua @@ -204,7 +204,8 @@ do }, closeImage):align("right") self.closeButton.clicked = function(self, x, y, button) if button == pop.constants.left_mouse then - return self.parent:close() + self.parent:close() + return true end end self.data.header_width_reduction = self.data.header_width_reduction + buttonSize @@ -218,7 +219,8 @@ do }, maximizeImage):align("right") self.maximizeButton.clicked = function(self, x, y, button) if button == pop.constants.left_mouse then - return self.parent:maximize() + self.parent:maximize() + return true end end self.data.header_width_reduction = self.data.header_width_reduction + buttonSize @@ -232,7 +234,8 @@ do }, minimizeImage):align("right") self.minimizeButton.clicked = function(self, x, y, button) if button == pop.constants.left_mouse then - return self.parent:minimize() + self.parent:minimize() + return true end end self.data.header_width_reduction = self.data.header_width_reduction + buttonSize diff --git a/elements/window.moon b/elements/window.moon index e472cb3..30cf4be 100644 --- a/elements/window.moon +++ b/elements/window.moon @@ -56,19 +56,21 @@ class window extends element @closeButton.clicked = (x, y, button) => if button == pop.constants.left_mouse @parent\close! + return true @data.header_width_reduction += buttonSize if @data.maximizeable @maximizeButton = pop.box(@, {w: buttonSize, h: buttonSize, horizontalMargin: @data.header_width_reduction, type: "box (window maximize button)"}, maximizeImage)\align "right" @maximizeButton.clicked = (x, y, button) => if button == pop.constants.left_mouse @parent\maximize! - --return nil --probably not needed + return true @data.header_width_reduction += buttonSize if @data.minimizeable @minimizeButton = pop.box(@, {w: buttonSize, h: buttonSize, horizontalMargin: @data.header_width_reduction, type: "box (window minimize button)"}, minimizeImage)\align "right" @minimizeButton.clicked = (x, y, button) => if button == pop.constants.left_mouse @parent\minimize! + return true @data.header_width_reduction += buttonSize height = @title\getHeight! + 1 diff --git a/init.lua b/init.lua index 61370dd..efb2714 100644 --- a/init.lua +++ b/init.lua @@ -306,10 +306,16 @@ pop.mousereleased = function(x, y, button, element) if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then if element.clicked then clickedHandled = element:clicked(x - element.data.x, y - element.data.y, button) + if clickedHandled ~= false then + log(" " .. tostring(clickedHandled) .. " (click handled)", tostring(element) .. " (" .. tostring(element.data.type) .. ")") + end end end if element.mousereleased then mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button) + if mousereleasedHandled ~= false then + log(" " .. tostring(mousereleasedHandled) .. " (release handled)", tostring(element) .. " (" .. tostring(element.data.type) .. ")") + end end if clickedHandled ~= false or mousereleasedHandled ~= false then return clickedHandled, mousereleasedHandled diff --git a/init.moon b/init.moon index a591b66..3b31a58 100644 --- a/init.moon +++ b/init.moon @@ -282,9 +282,10 @@ pop.mousemoved = (x, y, dx, dy, element=pop.screen) -> -- if we're hovering over something different, log it if element == pop.screen and pop.hovered != previously_hovered log " pop.hovered: #{pop.hovered} (#{pop.hovered.data.type})" + -- @todo This is where we call previously_hovered\hovered false, and pop.hovered\hovered true + -- There may be an issue where we are trying only on the lowest object in the hierarchy and we need to check multiple... - --- @todo Implement a way for an element to attach itself to `love.mousemoved()` events? - -- checking element against pop.screen so that this only gets called once + -- checks element == pop.screen so this only gets called once at the end of recursion if pop.focused and pop.focused.mousemoved and element == pop.screen return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy @@ -397,9 +398,13 @@ pop.mousereleased = (x, y, button, element) -> if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) if element.clicked clickedHandled = element\clicked x - element.data.x, y - element.data.y, button + if clickedHandled != false + log " #{clickedHandled} (click handled)", "#{element} (#{element.data.type})" -- a focused element needs to know when it has been released no matter what! if element.mousereleased mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button + if mousereleasedHandled != false + log " #{mousereleasedHandled} (release handled)", "#{element} (#{element.data.type})" if clickedHandled != false or mousereleasedHandled != false return clickedHandled, mousereleasedHandled