Gspöt - retained GUI lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gspöt - formerly Yet another stateful GUI

Post by trubblegum » Fri Nov 30, 2012 10:18 am

You could override input.focus()
Out of the box, the inherited focus() function (in Gspot.util) is :

Code: Select all

element.focus = function(this)
    this.Gspot:setfocus(this)
end
.. so you could override that right after you include the lib, or use something like:

Code: Select all

myfocusfunc = function(this)
    this.Gspot.util.focus(this)
    // do stuff
end

input.focus = myfocusfunc
I don't see why this wouldn't work :

Code: Select all

input = gui:input()
input:focus()
if gui.focus == input then ... end
essentially, element:focus() passes a reference to itself over to the gui container using Gspot:setfocus(this) which does this.focus = element, so that Gspot.focus == element.

User avatar
Karai17
Party member
Posts: 906
Joined: Sun Sep 02, 2012 10:46 pm

Re: Gspöt - retained GUI lib

Post by Karai17 » Fri Nov 30, 2012 11:22 pm

Thanks for the reply! I'll take a look at your examples and see if I can get something working. :)

In the mean time, I have found another issue I am a bit confused by. I have a screen/gamestate system set up. When I switch to the next screen, the gui stays persistant and doesn't go away. You have a mention of doing something like mainmenu = gui() but I don't really understand how that is supposed to help :\

Could you explain in a little more detail how Gspot works with gamestates? Thanks!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gspöt - retained GUI lib

Post by trubblegum » Sat Dec 01, 2012 12:32 am

Well, there are at least a couple of ways you can work it.
One, which I recommend, is to create a new instance for each gamestate. I used something like state[currentstate].gui:update(dt) and state[currentstate].gui:draw()
The key here is to only update and draw the relevant GUI.
Another way to go about it would be to create a root gamestate container for each gamestate (like gui:group("mainmenu") etc), and toggle visibility for each one along with the corresponding gamestate.
Advantages with the first method are that it reduces load by keeping unused elements out of the current gamestate, and may be easier to organize elements with. Any Gspot instance which is not currently in use will retain its state while inactive, so you may have to reconstruct a GUI when you enter its relevant gamestate, to ensure consistency.
A disadvantage is that you could end up with a bit of a bulky structure :

Code: Select all

game{
    states{
        menu{
            gui{}
            ...
        }
        ...
    }
    ...
}

User avatar
Karai17
Party member
Posts: 906
Joined: Sun Sep 02, 2012 10:46 pm

Re: Gspöt - retained GUI lib

Post by Karai17 » Sat Dec 01, 2012 12:37 am

Hrm... Here is the code I am currently working with: https://github.com/karai17/love-tanks/t ... ter/client

Which method would you suggest that would work best with my gamestate (screen) controller?

Edit: Are you suggesting somethign like this:

Code: Select all

-- main controller
gui = require 'Gspot'

--[[ CONTROLLER MAGIC ]] --




-- some gamestate file
local function load(self)
    self.gui = gui()
end

local function update(self, dt)
    self.gui:update(dt)
end

local function draw(self)
    self.gui:draw()
end
OH HEY THAT WORKED! :O

Thanks for the help, it is much appreciated! :)
Last edited by Karai17 on Sat Dec 01, 2012 1:15 am, edited 2 times in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gspöt - retained GUI lib

Post by trubblegum » Sat Dec 01, 2012 1:13 am

Looks good to me (just that errant quote, but I'm sure you caught it)
All the best

User avatar
SiENcE
Party member
Posts: 791
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Gspöt - retained GUI lib

Post by SiENcE » Tue Dec 11, 2012 9:43 am

Hey trubblegum,

i reported two problems to your bugtracker.

https://github.com/trubblegum/Gspot/issues/3

It seems that love2d is slow as hell when using 'love.graphics.print' and 'love.graphics.printf' :-(.

I want to add text to my scrollbox, so that this text is added at the bottom. Scrollbox should scroll up on line.

My scrollbox code:

Code: Select all

	-- scrollgroup's children, excepting its scrollbar, will scroll
        -- scrollgroup will create its own scrollbar
	self.textbox = self.gspot:scrollgroup(nil, {self.pos.x+60, self.pos.y+286, 352-16, 56}, nil, 'vertical')
        -- scrollgroup.scrollh is the horizontal scrollbar
	self.textbox.scrollv.tip = 'Scroll (mouse or wheel)'
        -- texter itself
	self.texter = self.gspot:text('', {w = self.textbox.pos.w}, self.textbox) 

Code: Select all

-- add some new text to the textbox
function GameGui:addSomeText(text)
	if text and string.len(text) > 0 then
		local newtext = self.texter.label .. text .. '\n'
		-- number of lines
		local lines=0
		for i in newtext:gmatch("\n") do lines=lines+1 end
		self.texter.label = newtext
		if lines > 6 then
			self.textbox.scrollv.values.max = self.textbox.scrollv.values.max+8
			self.textbox.scrollv.values.current = self.textbox.scrollv.values.max
		end
	end
	print(text)
end
Testcode:

Code: Select all

	for i=1, 200 do
		self:addSomeText(i.. " 345678901234567890123456789012345678")
	end 
thx. & cheers

User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gspöt - retained GUI lib

Post by trubblegum » Tue Dec 11, 2012 11:39 am

It's pretty unclear what the problem is.

Try this?

Code: Select all

scrollgroup.scrollv.values.max = scrollgroup:getmaxh() - scrollgroup.pos.h
Or destroy and replace the text object, or append a new text object using, assuming you may want to add and remove text.
Honestly, scrollgroups are a bit finicky, and it's sometimes better to reconstruct them than try to manipulate them beyond fairly basic stuff.

Not sure about your scaling and framerate issues. Suspect this might be a limitation of scissors.

User avatar
SiENcE
Party member
Posts: 791
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Gspöt - retained GUI lib

Post by SiENcE » Tue Dec 11, 2012 3:40 pm

Thanks i will try this.

My biggest problem is the rendering performance when using 'love.graphics.print' and 'love.graphics.printf'. It's so slow :-/.

User avatar
Karai17
Party member
Posts: 906
Joined: Sun Sep 02, 2012 10:46 pm

Re: Gspöt - retained GUI lib

Post by Karai17 » Thu Dec 13, 2012 9:34 am

So I think I found a pretty significant bug in Gspot. If you look at the following example, you'll notice I have 3 scrollgroups and 3 buttons. Each button sends text to the appropriate scrollgroup. The problem here is that it looks like you can only have a single scrollgroup at any one time on screen that is functional. It will always be the last one created. All of the ones created prior seem to be completely borked. They do not have scroll bars and children cannot be added to them.

Any ideas on how to fix this? I am working on a chatbox that requires multiple scrollgroups to separate content into channels and currently only the last one works. :(

Code: Select all

gui = require('Gspot')
font = love.graphics.newFont(12)

love.load = function()
	love.graphics.setFont(font)
	sometext = 'Lorem ipsum dolor sit amet.'
	
	scrollgroup		= gui:scrollgroup(nil, {0, gui.style.unit, 128, 128})
	scrollgroup2	= gui:scrollgroup(nil, {150, gui.style.unit, 128, 128})
	scrollgroup3	= gui:scrollgroup(nil, {300, gui.style.unit, 128, 128})
	
	button	= gui:button('text', {x=0, y=192, w=56, h=16})
	button2	= gui:button('text', {x=150, y=192, w=56, h=16})
	button3	= gui:button('text', {x=300, y=192, w=56, h=16})
	
	button.click = function()
		scrollgroup:addchild(gui:text(sometext, {w=128}), 'vertical')
	end
	
	button2.click = function()
		scrollgroup2:addchild(gui:text(sometext, {w=128}), 'vertical')
	end
	
	button3.click = function()
		scrollgroup3:addchild(gui:text(sometext, {w=128}), 'vertical')
	end
end

love.update = function(dt)
	gui:update(dt)
end

love.draw = function()
	gui:draw()
end

love.keypressed = function(key, code)
	gui:keypress(key, code)
end

love.mousepressed = function(x, y, button)
	gui:mousepress(x, y, button)
end
love.mousereleased = function(x, y, button)
	gui:mouserelease(x, y, button)
end
Also, if I may add, if there is a plan to fix the scrollgroup's finickiness, could I request some added features such as:
  • Ability to align text/children in an element (example: right justify or align from bottom)
  • Ability to prepend children instead of appending them
  • Scroll from bottom (think a chat window in virtually every game ever)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gspöt - retained GUI lib

Post by trubblegum » Thu Dec 13, 2012 12:29 pm

I won't be adding to Gspot in the foreseeable future. The scrollgroup bug was a pretty glaring issue, so I fixed it (get the latest from github), but I'm not really working on this any more. I realise that that there are a few thing about it that are less than ideal, and when I get some time (and inclination) to make improvements, I will take suggestions into account, of course. Until then, the stuff you're asking for is pretty easy to do yourself.

See above for scrolling to the bottom of a scrollgroup.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests