Löve Frames - A GUI Library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Rishavs
Party member
Posts: 103
Joined: Sat Oct 17, 2009 5:29 am
Contact:

Re: Löve Frames - A GUI Library

Post by Rishavs »

The buttons are getting rendered but the click event is not firing.
LaggyNewbie
Prole
Posts: 6
Joined: Sun Oct 11, 2009 1:53 am

Re: Löve Frames - A GUI Library

Post by LaggyNewbie »

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?
User avatar
Nikolai Resokav
Party member
Posts: 140
Joined: Wed Apr 28, 2010 12:51 am
Location: United States

Re: Löve Frames - A GUI Library

Post by Nikolai Resokav »

Rishavs wrote:The buttons are getting rendered but the click event is not firing.
Can you post a .love of your project?
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?
Love Frames performs several tasks when you require it, and I haven't really taken the time to optimize any of them.
LaggyNewbie
Prole
Posts: 6
Joined: Sun Oct 11, 2009 1:53 am

Re: Löve Frames - A GUI Library

Post by LaggyNewbie »

I think I figured out the problem. There were global variable names being shared by both libraries (specifically the utf8.lua file) but not throwing any errors. I ended up changing the serialize library to Tserial.lua which doesn't appear to have any naming conflicts with the love frame library
Ford_Prefect
Prole
Posts: 31
Joined: Sun Dec 30, 2012 7:14 pm

Re: Löve Frames - A GUI Library

Post by Ford_Prefect »

I have the same problem as Rishavs - the .OnClick callback for buttons does not work.

Here's my code (relevant parts on top):

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
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).

I'll attach the .love
Attachments
solsysgen.love
(140.51 KiB) Downloaded 194 times
User avatar
Nikolai Resokav
Party member
Posts: 140
Joined: Wed Apr 28, 2010 12:51 am
Location: United States

Re: Löve Frames - A GUI Library

Post by Nikolai Resokav »

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):

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
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).

I'll attach the .love
You need to add the mousepressed and mousereleased callbacks:

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
Ford_Prefect
Prole
Posts: 31
Joined: Sun Dec 30, 2012 7:14 pm

Re: Löve Frames - A GUI Library

Post by Ford_Prefect »

Nikolai Resokav wrote:
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):

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
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).

I'll attach the .love
You need to add the mousepressed and mousereleased callbacks:

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.

edit: While I'm at it, I have another question.
If I create slider and set it's default value, how do I get the slider to actually be at the corresponding point for that value? It's always stuck to the very left (horizontal slider) for me.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Löve Frames - A GUI Library

Post by Doctory »

is it possible to rename love frames when requiring it?
User avatar
Nikolai Resokav
Party member
Posts: 140
Joined: Wed Apr 28, 2010 12:51 am
Location: United States

Re: Löve Frames - A GUI Library

Post by Nikolai Resokav »

Doctory wrote:is it possible to rename love frames when requiring it?
Love Frames is returned when you require it, so something like this should work:

Code: Select all

gui = require("path.to.loveframes")
fmra
Prole
Posts: 11
Joined: Fri Nov 29, 2013 9:39 pm

Re: Löve Frames - A GUI Library

Post by fmra »

I'm trying to retrieve the name of an object using GetHoverObject, but having iterated through the table it returns, the names I gave the objects do not exist. Closest I get is "instance of class loveframes_object_imagebutton" or similar. I'm trying to retrieve the name to match it against a table value (the objects name). See "obj[x]"

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
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests