Re: Löve Frames - A GUI Library
Posted: Mon Dec 01, 2014 6:00 am
The buttons are getting rendered but the click event is not firing.
Can you post a .love of your project?Rishavs wrote:The buttons are getting rendered but the click event is not firing.
Love Frames performs several tasks when you require it, and I haven't really taken the time to optimize any of them.LaggyNewbie wrote:I have a game that does some deserializing of data using a serialize.lua library found on the forums.
With a os.clock() taken before and after running 1 deserialize() operation, the time is about .001 seconds.
Just by adding:
require("libs.loveframes")
and not even adding the update or draw events required by loveframes, the same deserialize() function process jumps to taking .7 seconds to complete.
Any idea why just including a require to loveframes makes my deserialize() operation increase by a couple orders of magnitude?
Code: Select all
function love.load()
require("lib.Frames")
button_circles = loveframes.Create("button")
button_circles:SetWidth(200)
button_circles:SetText("Toggle Lines")
button_circles.x = 20
button_circles.y = 20
circles = false
button_circles.OnClick = function ()
circles = not circles
button_circles:SetText("test")
end
love.window.setMode(1280, 800)
math.randomseed(os.time())
math.random(); math.random(); math.random()
planet = {}
t = 0
--planets
planet.number = math.random(10)
sun = {}
sun.radius = math.random(30, 50)
sun.x = 1280/2
sun.y = 800/2
for i = 1, planet.number do
planet[i] = {}
planet[i].radius = math.random(5, sun.radius * 0.5)
if i == 1 then
planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100)
else
planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75)
end
planet[i].T = math.pow(planet[i].distance, 3/2) * 10
planet[i].t = t + math.random(100000)
planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T)
planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T)
end
end
function love.update()
for i = 1, planet.number do
planet[i].t = planet[i].t + 1
planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T)
planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T)
end
loveframes.update()
end
function love.draw()
love.graphics.circle("fill", sun.x, sun.y, sun.radius)
for i = 1, planet.number do
love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius)
if circles then
love.graphics.circle("line", sun.x, sun.y, planet[i].distance)
end
end
loveframes.draw()
end
You need to add the mousepressed and mousereleased callbacks:Ford_Prefect wrote:I have the same problem as Rishavs - the .OnClick callback for buttons does not work.
Here's my code (relevant parts on top):
It works flawlessly if I use .OnMouseEnter instead. It also works flawlessly in another older project, where I have _exactly_ the same syntax (and the libs were copied over from there).Code: Select all
function love.load() require("lib.Frames") button_circles = loveframes.Create("button") button_circles:SetWidth(200) button_circles:SetText("Toggle Lines") button_circles.x = 20 button_circles.y = 20 circles = false button_circles.OnClick = function () circles = not circles button_circles:SetText("test") end love.window.setMode(1280, 800) math.randomseed(os.time()) math.random(); math.random(); math.random() planet = {} t = 0 --planets planet.number = math.random(10) sun = {} sun.radius = math.random(30, 50) sun.x = 1280/2 sun.y = 800/2 for i = 1, planet.number do planet[i] = {} planet[i].radius = math.random(5, sun.radius * 0.5) if i == 1 then planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100) else planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75) end planet[i].T = math.pow(planet[i].distance, 3/2) * 10 planet[i].t = t + math.random(100000) planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T) planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T) end end function love.update() for i = 1, planet.number do planet[i].t = planet[i].t + 1 planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T) planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T) end loveframes.update() end function love.draw() love.graphics.circle("fill", sun.x, sun.y, sun.radius) for i = 1, planet.number do love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius) if circles then love.graphics.circle("line", sun.x, sun.y, planet[i].distance) end end loveframes.draw() end
I'll attach the .love
Code: Select all
function love.mousepressed(x, y, button)
loveframes.mousepressed(x, y, button)
end
function love.mousereleased(x, y, button)
loveframes.mousereleased(x, y, button)
end
Many thanks. Much appreciated. Me fail.Nikolai Resokav wrote:You need to add the mousepressed and mousereleased callbacks:Ford_Prefect wrote:I have the same problem as Rishavs - the .OnClick callback for buttons does not work.
Here's my code (relevant parts on top):
It works flawlessly if I use .OnMouseEnter instead. It also works flawlessly in another older project, where I have _exactly_ the same syntax (and the libs were copied over from there).Code: Select all
function love.load() require("lib.Frames") button_circles = loveframes.Create("button") button_circles:SetWidth(200) button_circles:SetText("Toggle Lines") button_circles.x = 20 button_circles.y = 20 circles = false button_circles.OnClick = function () circles = not circles button_circles:SetText("test") end love.window.setMode(1280, 800) math.randomseed(os.time()) math.random(); math.random(); math.random() planet = {} t = 0 --planets planet.number = math.random(10) sun = {} sun.radius = math.random(30, 50) sun.x = 1280/2 sun.y = 800/2 for i = 1, planet.number do planet[i] = {} planet[i].radius = math.random(5, sun.radius * 0.5) if i == 1 then planet[i].distance = math.random(sun.radius + planet[i].radius + 20, i*100) else planet[i].distance = math.random(planet[i - 1].distance + planet[i].radius + 20, i*75) end planet[i].T = math.pow(planet[i].distance, 3/2) * 10 planet[i].t = t + math.random(100000) planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi/planet[i].T) planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi/planet[i].T) end end function love.update() for i = 1, planet.number do planet[i].t = planet[i].t + 1 planet[i].x = sun.x + planet[i].distance*math.sin(2*math.pi*planet[i].t/planet[i].T) planet[i].y = sun.y + planet[i].distance*math.cos(2*math.pi*planet[i].t/planet[i].T) end loveframes.update() end function love.draw() love.graphics.circle("fill", sun.x, sun.y, sun.radius) for i = 1, planet.number do love.graphics.circle("fill", planet[i].x, planet[i].y, planet[i].radius) if circles then love.graphics.circle("line", sun.x, sun.y, planet[i].distance) end end loveframes.draw() end
I'll attach the .love
Code: Select all
function love.mousepressed(x, y, button) loveframes.mousepressed(x, y, button) end function love.mousereleased(x, y, button) loveframes.mousereleased(x, y, button) end
Love Frames is returned when you require it, so something like this should work:Doctory wrote:is it possible to rename love frames when requiring it?
Code: Select all
gui = require("path.to.loveframes")
Code: Select all
if loveframes.util.GetHoverObject() then
obj = loveframes.util.GetHoverObject()
for k, v in ipairs(tbl) do
if obj[x] == v then
...
end
end
end