Gspöt - retained GUI lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Gspöt - retained GUI lib

Post by pgimeno »

Code: Select all

button.label = tostring(number)
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: Gspöt - retained GUI lib

Post by zenith »

I mean, how to update text string on separate gui:text element on button click?
ping pong
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Gspöt - retained GUI lib

Post by pgimeno »

Ah, well, same idea, just set the label of the gui:text element.

Code: Select all

function love.load()
	number=0
	text=gui:text(tostring(number))
	
	button=gui:button('Click me')
	function button.click(this,x,y)
		number=number+1
                text.label = tostring(number)
	end
end
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: Gspöt - retained GUI lib

Post by zenith »

thank you!
ping pong
Anase Skyrider
Prole
Posts: 16
Joined: Sun Jan 31, 2021 12:47 am

Re: Gspöt - retained GUI lib

Post by Anase Skyrider »

I'd love to see more updates on this library like: differentiating click from mousedown, clicks getting called on mouse-up instead of mouse-down, and easier ways to add those sorts of events to other frames. It took me quite a bit of digging to discover that the way to get a frame object to register hover (mousein) was to declare element.mousein = element, and then set element.mousein.enter/leave functions. As opposed to, say, calling a single function like element:registerHover(enter_funtion, leave_function) or something more developer-friendly like that.

The ability to set the drawing scale of an image would be most helpful, too.
Anase Skyrider
Prole
Posts: 16
Joined: Sun Jan 31, 2021 12:47 am

Re: Gspöt - retained GUI lib

Post by Anase Skyrider »

I'm not exactly an expert with this library, but changing Gspot.mousepress and Gspot.mouserelease to this appears to make clicks fire on mouse-up, and not cause anything else to break. A notable change I discovered with some testing is that if you make this.mousedt = 0 only when it registers a regular click, you won't see other mouse events contributing to double-clicking, only left-clicking contributes to detecting a double-click. Without that 2nd change, you can quickly right-click and then left-click to get a double-click.

Code: Select all

Gspot.mousepress = function(this, x, y, button)
	this:unfocus()
	if this.mousein then
		local element = this.mousein
		if element.elementtype ~= 'hidden' then element:getparent():setlevel() end
		if button == mouseL then
			if element.drag then
				this.drag = element
				element.offset = {x = x - element:getpos().x, y = y - element:getpos().y}
			end
		end
	end
end

Gspot.mouserelease = function(this, x, y, button)
	if this.drag then
		local element = this.drag
		if button == mouseR then
			if element.rdrop then element:rdrop(this.mouseover) end
			if this.mouseover and this.mouseover.rcatch then this.mouseover:rcatch(element.id) end
		else
			if element.drop then element:drop(this.mouseover) end
			if this.mouseover and this.mouseover.catch then this.mouseover:catch(element) end
		end
	end
	this.drag = nil
	if this.mousein then
		local element = this.mousein
		if button == mouseL then
			if this.mousedt < this.dblclickinterval and element.dblclick then element:dblclick(x, y, button)
			elseif element.click then element:click(x, y); this.mousedt = 0 end
		elseif button == mouseR and element.rclick then element:rclick(x, y)
		elseif button == 'wu' and element.wheelup then element:wheelup(x, y)
		elseif button == 'wd' and element.wheeldown then element:wheeldown(x, y)
		end
	end
end
I'm still figuring out how dragging works. Currently, my elements are getting set to a very distant position away from my mouse when I start dragging it, but this happens even when I undo these changes, so I'm not sure what the cause is.
Anase Skyrider
Prole
Posts: 16
Joined: Sun Jan 31, 2021 12:47 am

Re: Gspöt - retained GUI lib

Post by Anase Skyrider »

The Gspot.util.containspoint function might need to be revisted. The detection for the bounds of the height of my text object was incorrect until I set pos.y to use the same formula for the one that changes pos.x. After changing it, my text would correctly detect when my mouse was supposed to be over it and register clicks correctly.

Old:

Code: Select all

pos.y = pos.y - math.floor(((this.style.unit - this.style.font:getHeight()) / 2) + 0.5)
New:

Code: Select all

pos.y = pos.y - math.floor((this.style.unit / 4) + 0.5)
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Gspöt - retained GUI lib

Post by pgimeno »

Anase Skyrider wrote: Mon Feb 01, 2021 11:06 pm I'd love to see more updates on this library like: differentiating click from mousedown, clicks getting called on mouse-up instead of mouse-down, and easier ways to add those sorts of events to other frames.
[...]
The ability to set the drawing scale of an image would be most helpful, too.
These are new features, and Gspöt is currently being maintained only to fix bugs and update to latest versions of Löve. There are libraries more advanced than Gspöt, see e.g. Slab.

Anase Skyrider wrote: Tue Feb 02, 2021 12:06 amA notable change I discovered with some testing is that if you make this.mousedt = 0 only when it registers a regular click, you won't see other mouse events contributing to double-clicking, only left-clicking contributes to detecting a double-click. Without that 2nd change, you can quickly right-click and then left-click to get a double-click.
Anase Skyrider wrote: Tue Feb 02, 2021 1:02 am The Gspot.util.containspoint function might need to be revisted.
I have pushed fixes for the text element click and for the doubleclick issues, thanks for the reports.
Anase Skyrider
Prole
Posts: 16
Joined: Sun Jan 31, 2021 12:47 am

Re: Gspöt - retained GUI lib

Post by Anase Skyrider »

Bug report (and solution): Tooltips applied to larger text elements will render the tooltip-text as small, but will measure the bounds of the box as if they're using the parent's bigger font. Replacing all tooltip-related instances of "element.style.font" with "this.style.font" (the font used by the tooltip) inside Gspot.draw() fixes the issue.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Gspöt - retained GUI lib

Post by pgimeno »

Fix pushed, thanks for the report!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests