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 »

Update : added element:update(dt)
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: Gspöt - formerly Yet another stateful GUI

Post by Gravy »

Hey trubblegum, thanks for this.

I want to use an image as a button label, and I see that this functionality exists but 'img' isn't included in the button constructor. Am I just misunderstanding how to use images here?
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 »

There are two ways to add an image, mostly because I haven't decided on what's the best way to do it yet.

The first is to make a button using id = gui:button() and then assign the image using gui:element(id).img = imgdata
The second is with gui:image(label, pos, img, optional parent) but at the moment this doesn't display label (that's why it's not in the examples, and it will be fixed in the next update)

In either case (at least for now) the image must be an imagedata such as is loaded by love using love.graphics.newImage()

I'm building in a shortcut for image buttons now, so check back soon.
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 »

Update :

- image(this, label, pos, img, parent) resizes the element to fit the image, and displays the image with no background, and a centered label below
- imgbutton(this, label, pos, img, parent) does not resize the element, centers the image, and displays with default interactive background behind the image, and label centered just below the top of the element

Both accept imageData as arg 4, or will do img = assert(love.graphics.newImage(img)) if type(img) == 'string'

Keep 'em coming :)
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: Gspöt - formerly Yet another stateful GUI

Post by Gravy »

That makes sense. I've been playing with this library all afternoon (my RPG has so many buttons now!), and I have one question and one suggestion:

Question: Is there a way for me to assign functions that are called when an element gains or loses focus? I think this would be easy for me to add but I just want to make sure it's not already there.

Suggestion: I think backspace should continue to delete things when held down for more than a half second (or some other fraction). People would have to add a gui:isdown() call, but it seems like a small price to pay.
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 »

there is a element:update(dt), which is called every update.
In very simplistic terms, you're probably looking at something like :

Code: Select all

gui:element(id).update = fuction(this, dt)
   if love.keyboard.isdown('backspace') then
      this.value = this.value:sub(1, this.value:len())
   end
end
Of course, you will want to provide for timing, which is why the gui passes dt along to the element.

Do you think it might be worth adding element.updateinterval to signal how often to call the behaviour?
I'm considering it.
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 »

Doh! The first question ..
Elements have focus at different levels, so I'm not sure how I'd go about adding start and stop events for each one, but I can give it some thought.

The "states" which the gui tracks are :
- gui.mousein - id of the topmost element under the pointer
- gui.mouseover - id of the topmost element under the pointer and the element being dragged. only not nil if an element is being dragged over another element.
- gui.focus - id of an input element which has focus

You can of course simulate mouseEnter and mouseLeave events with something like :

Code: Select all

element = gui:element(id)
element.hasfocus = false
element.enter = function(this) print("I'm In!") end
element.leave = function(this) print("I'm Out!") end
element.update = function(this, dt)
   if this.id == this.Gspot.mousein then
      if not this.hasfocus then
         this:enter()
         this.hasfocus = true
      end
   else
      if this.hasfocus then
         this:leave()
         this.hasfocus = false
      end
   end
end
Come to think of it, it would be fairly straightforward to implement, but something for tomorrow, I think - glad you brought it up.

Come to think of it more, it is my job to provide that functionality for you :o: but still a job for tomorrow :P
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: Gspöt - formerly Yet another stateful GUI

Post by Gravy »

Great!

I'm not sure the updateinterval would be used enough to warrant its own per-element setting, especially since there would almost always be an alternate solution using dt.

However, I do think that every element should have an optional font override. Otherwise someone will have to make a GUI for every font (I think). It would just require you to add something like:

Code: Select all

if element.font then
love.graphics.setFont(element.font)
else
love.graphics.setFont(this.font)
end
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Gspöt - formerly Yet another stateful GUI

Post by Kingdaro »

God I love the names of these libraries. Firstly we have Löve, even. and then there's:

LUBE
AnAL
HUMP
SECS
HardonCollider

i love you people
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 »

Gravy wrote:every element should have an optional font override
Colour too!
More for the ToDo list :)
Kingdaro wrote: LUBE
AnAL
HUMP
SECS
HardonCollider
It's good to smile while you work :awesome:
Löve you too, man :3
Post Reply

Who is online

Users browsing this forum: No registered users and 65 guests