From 048e8c796131061f6ae44dc919b11cbdf37363ae Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sun, 13 Aug 2017 18:15:08 -0700 Subject: [PATCH] #39 repaired --- elements/window.lua | 1 + elements/window.moon | 1 + init.lua | 23 +++++++++++++---------- init.moon | 4 ++-- main.lua | 14 ++++++++++++-- main.moon | 4 +++- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/elements/window.lua b/elements/window.lua index ad172ee..7b05f29 100644 --- a/elements/window.lua +++ b/elements/window.lua @@ -325,6 +325,7 @@ do self.header.mousereleased = function(self, x, y, button) if button == pop.constants.left_mouse then selected = false + pop.focused = false return true end return false diff --git a/elements/window.moon b/elements/window.moon index b812811..e472cb3 100644 --- a/elements/window.moon +++ b/elements/window.moon @@ -152,6 +152,7 @@ class window extends element @header.mousereleased = (x, y, button) => if button == pop.constants.left_mouse selected = false + pop.focused = false -- maybe it should check if it is focused first? return true return false diff --git a/init.lua b/init.lua index 0b4804c..61370dd 100644 --- a/init.lua +++ b/init.lua @@ -300,17 +300,20 @@ pop.mousereleased = function(x, y, button, element) end else log("mousereleased", x, y, button) - if element == pop.focused then - 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) + do + element = pop.focused + if element then + 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) + end + end + if element.mousereleased then + mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button) + end + if clickedHandled ~= false or mousereleasedHandled ~= false then + return clickedHandled, mousereleasedHandled end - end - if element.mousereleased then - mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button) - end - if clickedHandled ~= false or mousereleasedHandled ~= false then - return clickedHandled, mousereleasedHandled end end pop.mousereleased(x, y, button, pop.screen) diff --git a/init.moon b/init.moon index e279a87..a591b66 100644 --- a/init.moon +++ b/init.moon @@ -374,7 +374,7 @@ pop.mousereleased = (x, y, button, element) -> if element.mousereleased mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button - -- if we clicked, we're focused! + -- if we clicked (AND returned true), we're focused! if clickedHandled != false log " #{clickedHandled} (click handled)", "#{element} (#{element.data.type})" if clickedHandled @@ -393,7 +393,7 @@ pop.mousereleased = (x, y, button, element) -> else log "mousereleased", x, y, button - if element == pop.focused + if element = pop.focused 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 diff --git a/main.lua b/main.lua index f3d0ab9..8de2c24 100644 --- a/main.lua +++ b/main.lua @@ -51,7 +51,9 @@ love.load = function() h = 10 }):align("center", "bottom") pop.text(centerBox, "Align me!"):align("right", "top") - pop.window(centerBox):align("right", "bottom") + pop.window(centerBox, { + closeable = true + }):align("right", "bottom") centerBox:setPadding(5) pop.box(centerBox, { w = 10, @@ -119,7 +121,7 @@ love.load = function() 100 } }, "Align me!"):align("right", "top") - return pop.window(centerBox, { + pop.window(centerBox, { titleColor = { 0, 0, @@ -139,6 +141,14 @@ love.load = function() 100 } }):align("right", "bottom") + pop.window(centerBox, { + containMethod = "title", + w = 125 + }, "Title can't leave") + return pop.window(centerBox, { + containMethod = "body", + w = 125 + }, "Body can't leave") end local new_method new_method = function() diff --git a/main.moon b/main.moon index befaece..d093109 100644 --- a/main.moon +++ b/main.moon @@ -24,7 +24,7 @@ love.load = -> pop.box(centerBox)\align("left", "bottom")\setSize 5, 5 pop.box(centerBox, {w: 25, h: 10})\align "center", "bottom" pop.text(centerBox, "Align me!")\align "right", "top" - pop.window(centerBox)\align "right", "bottom" + pop.window(centerBox, {closeable: true})\align "right", "bottom" centerBox\setPadding 5 @@ -36,6 +36,8 @@ love.load = -> pop.box(centerBox, {w: 25, h: 10, background: {0, 0, 255, 100}})\align "center", "bottom" pop.text(centerBox, {color: {0, 0, 255, 100}}, "Align me!")\align "right", "top" pop.window(centerBox, {titleColor: {0, 0, 0, 150}, titleBackground: {0, 0, 255, 100}, windowBackground: {200, 200, 255, 100}})\align "right", "bottom" + pop.window(centerBox, {containMethod: "title", w: 125}, "Title can't leave") + pop.window(centerBox, {containMethod: "body", w: 125}, "Body can't leave") new_method = -> partsGrid = pop.dynamicGrid!