mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
fixed close buttons
This commit is contained in:
parent
16b9d28973
commit
e54fe6cb43
@ -43,7 +43,6 @@ function love.load()
|
|||||||
w2:setClose(false)
|
w2:setClose(false)
|
||||||
local t2 = pop.text("Click here to toggle close\nbutton on this window."):setMargin(10):setColor(0,0,0)
|
local t2 = pop.text("Click here to toggle close\nbutton on this window."):setMargin(10):setColor(0,0,0)
|
||||||
t2.clicked = function()
|
t2.clicked = function()
|
||||||
print("CALLED") --NOTE not working!
|
|
||||||
w2:setClose(not w2:hasClose())
|
w2:setClose(not w2:hasClose())
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -106,6 +105,11 @@ function love.keypressed(key)
|
|||||||
debugDraw = not debugDraw
|
debugDraw = not debugDraw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (key == "w") and (not handled) then
|
||||||
|
local w = pop.window()
|
||||||
|
w.title:align("center")
|
||||||
|
end
|
||||||
|
|
||||||
if (key == "escape") and (not handled) then
|
if (key == "escape") and (not handled) then
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
end
|
end
|
||||||
|
@ -17,12 +17,7 @@ local path = sub(..., 1, len(...) - len("/window"))
|
|||||||
local element = require(tostring(path) .. "/element")
|
local element = require(tostring(path) .. "/element")
|
||||||
local box = require(tostring(path) .. "/box")
|
local box = require(tostring(path) .. "/box")
|
||||||
local text = require(tostring(path) .. "/text")
|
local text = require(tostring(path) .. "/text")
|
||||||
local closeImage = {
|
local closeImage = graphics.newImage(tostring(path) .. "/img/close.png")
|
||||||
100,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
80
|
|
||||||
}
|
|
||||||
local left = 1
|
local left = 1
|
||||||
local mousemoved_event = true
|
local mousemoved_event = true
|
||||||
do
|
do
|
||||||
@ -196,6 +191,10 @@ do
|
|||||||
setClose = function(self, enabled)
|
setClose = function(self, enabled)
|
||||||
if enabled then
|
if enabled then
|
||||||
self.close = box(self, closeImage)
|
self.close = box(self, closeImage)
|
||||||
|
self.close.clicked = function()
|
||||||
|
self:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
local height = self.head:getHeight()
|
local height = self.head:getHeight()
|
||||||
self.close:align("right"):setSize(height, height)
|
self.close:align("right"):setSize(height, height)
|
||||||
self.head:setWidth(self.w - height)
|
self.head:setWidth(self.w - height)
|
||||||
@ -250,7 +249,7 @@ do
|
|||||||
end
|
end
|
||||||
_class_0.__parent.__init(self, parent)
|
_class_0.__parent.__init(self, parent)
|
||||||
self.head = box(self, tBackground)
|
self.head = box(self, tBackground)
|
||||||
self.title = text(self, title, tColor)
|
self.title = text(self.head, title, tColor)
|
||||||
self.window = box(self, wBackground)
|
self.window = box(self, wBackground)
|
||||||
self.close = box(self, closeImage)
|
self.close = box(self, closeImage)
|
||||||
local height = self.title:getHeight()
|
local height = self.title:getHeight()
|
||||||
@ -266,7 +265,6 @@ do
|
|||||||
}
|
}
|
||||||
self.titleOverflow = "trunicate"
|
self.titleOverflow = "trunicate"
|
||||||
self.close.clicked = function()
|
self.close.clicked = function()
|
||||||
print("CLOSE WAS CLICKED")
|
|
||||||
self:delete()
|
self:delete()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -17,12 +17,7 @@ local path = sub(..., 1, len(...) - len("/window"))
|
|||||||
local element = require(tostring(path) .. "/element")
|
local element = require(tostring(path) .. "/element")
|
||||||
local box = require(tostring(path) .. "/box")
|
local box = require(tostring(path) .. "/box")
|
||||||
local text = require(tostring(path) .. "/text")
|
local text = require(tostring(path) .. "/text")
|
||||||
local closeImage = {
|
local closeImage = graphics.newImage(tostring(path) .. "/img/close.png")
|
||||||
100,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
80
|
|
||||||
}
|
|
||||||
local left = 1
|
local left = 1
|
||||||
local mousemoved_event = true
|
local mousemoved_event = true
|
||||||
do
|
do
|
||||||
@ -196,6 +191,10 @@ do
|
|||||||
setClose = function(self, enabled)
|
setClose = function(self, enabled)
|
||||||
if enabled then
|
if enabled then
|
||||||
self.close = box(self, closeImage)
|
self.close = box(self, closeImage)
|
||||||
|
self.close.clicked = function()
|
||||||
|
self:delete()
|
||||||
|
return true
|
||||||
|
end
|
||||||
local height = self.head:getHeight()
|
local height = self.head:getHeight()
|
||||||
self.close:align("right"):setSize(height, height)
|
self.close:align("right"):setSize(height, height)
|
||||||
self.head:setWidth(self.w - height)
|
self.head:setWidth(self.w - height)
|
||||||
@ -250,7 +249,7 @@ do
|
|||||||
end
|
end
|
||||||
_class_0.__parent.__init(self, parent)
|
_class_0.__parent.__init(self, parent)
|
||||||
self.head = box(self, tBackground)
|
self.head = box(self, tBackground)
|
||||||
self.title = text(self, title, tColor)
|
self.title = text(self.head, title, tColor)
|
||||||
self.window = box(self, wBackground)
|
self.window = box(self, wBackground)
|
||||||
self.close = box(self, closeImage)
|
self.close = box(self, closeImage)
|
||||||
local height = self.title:getHeight()
|
local height = self.title:getHeight()
|
||||||
@ -266,7 +265,6 @@ do
|
|||||||
}
|
}
|
||||||
self.titleOverflow = "trunicate"
|
self.titleOverflow = "trunicate"
|
||||||
self.close.clicked = function()
|
self.close.clicked = function()
|
||||||
print("CLOSE WAS CLICKED")
|
|
||||||
self:delete()
|
self:delete()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ element = require "#{path}/element"
|
|||||||
box = require "#{path}/box"
|
box = require "#{path}/box"
|
||||||
text = require "#{path}/text"
|
text = require "#{path}/text"
|
||||||
|
|
||||||
closeImage = {100, 0, 0, 80} --graphics.newImage "#{path}/img/close.png"
|
closeImage = graphics.newImage "#{path}/img/close.png"
|
||||||
|
|
||||||
-- version compatibility
|
-- version compatibility
|
||||||
left = 1 -- what is the left mouse button?
|
left = 1 -- what is the left mouse button?
|
||||||
@ -34,8 +34,9 @@ class window extends element
|
|||||||
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
||||||
super parent
|
super parent
|
||||||
|
|
||||||
|
-- NOTE @title having @head as its parent might break things horribly
|
||||||
@head = box @, tBackground -- title box at top
|
@head = box @, tBackground -- title box at top
|
||||||
@title = text @, title, tColor -- text at top
|
@title = text @head, title, tColor -- text at top
|
||||||
@window = box @, wBackground -- main window area
|
@window = box @, wBackground -- main window area
|
||||||
@close = box @, closeImage -- close button
|
@close = box @, closeImage -- close button
|
||||||
|
|
||||||
@ -55,7 +56,6 @@ class window extends element
|
|||||||
@titleOverflow = "trunicate" -- defaults to trunicating title to fit in window
|
@titleOverflow = "trunicate" -- defaults to trunicating title to fit in window
|
||||||
|
|
||||||
@close.clicked = ->
|
@close.clicked = ->
|
||||||
print "CLOSE WAS CLICKED"
|
|
||||||
@delete!
|
@delete!
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@ -261,15 +261,18 @@ class window extends element
|
|||||||
setClose: (enabled) =>
|
setClose: (enabled) =>
|
||||||
if enabled
|
if enabled
|
||||||
@close = box @, closeImage
|
@close = box @, closeImage
|
||||||
|
@close.clicked = ->
|
||||||
|
@delete!
|
||||||
|
return true
|
||||||
height = @head\getHeight!
|
height = @head\getHeight!
|
||||||
@close\align("right")\setSize height, height
|
@close\align("right")\setSize height, height
|
||||||
@head\setWidth @w - height
|
@head\setWidth @w - height
|
||||||
@title\align! -- new might not be working?
|
@title\align!
|
||||||
insert @child, @close
|
insert @child, @close
|
||||||
else
|
else
|
||||||
@close\delete!
|
@close\delete!
|
||||||
@head\setWidth @w
|
@head\setWidth @w
|
||||||
@title\align! -- new might not be working?
|
@title\align!
|
||||||
@close = false
|
@close = false
|
||||||
|
|
||||||
return @
|
return @
|
||||||
|
Loading…
Reference in New Issue
Block a user