implemented moveable option for windows

This commit is contained in:
Paul Liverman III 2017-08-13 18:59:18 -07:00
parent b7ec6cc77f
commit 5a6891ea7d
4 changed files with 16 additions and 5 deletions

View File

@ -155,6 +155,9 @@ do
if self.data.titleBar == nil then if self.data.titleBar == nil then
self.data.titleBar = true self.data.titleBar = true
end end
if self.data.moveable == nil then
self.data.moveable = true
end
if self.data.maximizeable == nil then if self.data.maximizeable == nil then
self.data.maximizeable = false self.data.maximizeable = false
end end
@ -315,7 +318,7 @@ do
return false return false
end end
self.header.mousepressed = function(self, x, y, button) 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 local grandparent = self.parent.parent
table.insert(grandparent.child, table.remove(grandparent.child, grandparent:indexOf(self.parent))) table.insert(grandparent.child, table.remove(grandparent.child, grandparent:indexOf(self.parent)))
selected = true selected = true
@ -328,7 +331,9 @@ do
self.header.mousereleased = function(self, x, y, button) self.header.mousereleased = function(self, x, y, button)
if button == pop.constants.left_mouse then if button == pop.constants.left_mouse then
selected = false selected = false
pop.focused = false if self == pop.focused then
pop.focused = false
end
return true return true
end end
return false return false

View File

@ -38,6 +38,7 @@ class window extends element
@data.maximized = false @data.maximized = false
@data.titleBar = true if @data.titleBar == nil @data.titleBar = true if @data.titleBar == nil
@data.moveable = true if @data.moveable == nil
@data.maximizeable = false if @data.maximizeable == nil @data.maximizeable = false if @data.maximizeable == nil
@data.minimizeable = false if @data.minimizeable == nil @data.minimizeable = false if @data.minimizeable == nil
@data.closeable = false if @data.closeable == 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.w = @data.w - @data.padding*2
@window_area.data.h = @data.h - @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) => @window_area.mousepressed = (x, y, button) =>
if button == pop.constants.left_mouse if button == pop.constants.left_mouse
grandparent = @parent.parent grandparent = @parent.parent
@ -142,7 +143,7 @@ class window extends element
return false return false
@header.mousepressed = (x, y, button) => @header.mousepressed = (x, y, button) =>
if button == pop.constants.left_mouse if @data.moveable and button == pop.constants.left_mouse
grandparent = @parent.parent grandparent = @parent.parent
table.insert grandparent.child, table.remove(grandparent.child, grandparent\indexOf @parent) table.insert grandparent.child, table.remove(grandparent.child, grandparent\indexOf @parent)
selected = true selected = true
@ -154,7 +155,8 @@ class window extends element
@header.mousereleased = (x, y, button) => @header.mousereleased = (x, y, button) =>
if button == pop.constants.left_mouse if button == pop.constants.left_mouse
selected = false selected = false
pop.focused = false -- maybe it should check if it is focused first? if @ == pop.focused
pop.focused = false
return true return true
return false return false

View File

@ -20,6 +20,9 @@ love.load = function()
pop.window({ pop.window({
maximizeable = true maximizeable = true
}, "Test Window #2"):align("center", "bottom") }, "Test Window #2"):align("center", "bottom")
pop.window({
moveable = false
}, "Immoveable!")
local centerBox = pop.box({ local centerBox = pop.box({
w = 200, w = 200,
h = 200 h = 200

View File

@ -14,6 +14,7 @@ love.load = ->
print testWindow.window_area print testWindow.window_area
pop.window({maximizeable: true}, "Test Window #2")\align "center", "bottom" pop.window({maximizeable: true}, "Test Window #2")\align "center", "bottom"
pop.window({moveable: false}, "Immoveable!")
-- alignment testing -- alignment testing
centerBox = pop.box({w: 200, h: 200}, {255, 255, 0, 120})\align "center", "center" centerBox = pop.box({w: 200, h: 200}, {255, 255, 0, 120})\align "center", "center"