diff --git a/elements/window.lua b/elements/window.lua index 1cacc5e..d14efab 100644 --- a/elements/window.lua +++ b/elements/window.lua @@ -155,6 +155,9 @@ do if self.data.titleBar == nil then self.data.titleBar = true end + if self.data.moveable == nil then + self.data.moveable = true + end if self.data.maximizeable == nil then self.data.maximizeable = false end @@ -315,7 +318,7 @@ do return false end self.header.mousepressed = function(self, x, y, button) - if button == pop.constants.left_mouse then + if self.data.moveable and button == pop.constants.left_mouse then local grandparent = self.parent.parent table.insert(grandparent.child, table.remove(grandparent.child, grandparent:indexOf(self.parent))) selected = true @@ -328,7 +331,9 @@ do self.header.mousereleased = function(self, x, y, button) if button == pop.constants.left_mouse then selected = false - pop.focused = false + if self == pop.focused then + pop.focused = false + end return true end return false diff --git a/elements/window.moon b/elements/window.moon index 30cf4be..03a4b21 100644 --- a/elements/window.moon +++ b/elements/window.moon @@ -38,6 +38,7 @@ class window extends element @data.maximized = false @data.titleBar = true if @data.titleBar == nil + @data.moveable = true if @data.moveable == nil @data.maximizeable = false if @data.maximizeable == nil @data.minimizeable = false if @data.minimizeable == nil @data.closeable = false if @data.closeable == nil @@ -86,7 +87,7 @@ class window extends element @window_area.data.w = @data.w - @data.padding*2 @window_area.data.h = @data.h - @data.padding*2 - -- window area steals mouse events to prevent propagation to elements under it + -- window area steals mouse events to prevent propagation to elements visibily underneath it (not within its hierarchy) @window_area.mousepressed = (x, y, button) => if button == pop.constants.left_mouse grandparent = @parent.parent @@ -142,7 +143,7 @@ class window extends element return false @header.mousepressed = (x, y, button) => - if button == pop.constants.left_mouse + if @data.moveable and button == pop.constants.left_mouse grandparent = @parent.parent table.insert grandparent.child, table.remove(grandparent.child, grandparent\indexOf @parent) selected = true @@ -154,7 +155,8 @@ 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? + if @ == pop.focused + pop.focused = false return true return false diff --git a/main.lua b/main.lua index b938650..2190f8e 100644 --- a/main.lua +++ b/main.lua @@ -20,6 +20,9 @@ love.load = function() pop.window({ maximizeable = true }, "Test Window #2"):align("center", "bottom") + pop.window({ + moveable = false + }, "Immoveable!") local centerBox = pop.box({ w = 200, h = 200 diff --git a/main.moon b/main.moon index eb937e6..2603d20 100644 --- a/main.moon +++ b/main.moon @@ -14,6 +14,7 @@ love.load = -> print testWindow.window_area pop.window({maximizeable: true}, "Test Window #2")\align "center", "bottom" + pop.window({moveable: false}, "Immoveable!") -- alignment testing centerBox = pop.box({w: 200, h: 200}, {255, 255, 0, 120})\align "center", "center"