Quickie [was: Immediate Mode Gui]

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ncarlson
Prole
Posts: 35
Joined: Wed Jul 20, 2011 4:00 pm

Re: Quickie [was: Immediate Mode Gui]

Post by ncarlson »

kikito wrote: I'm using 0.7.2 . Is your code only valid for 0.8.x?
Yes, and it requires a more recent build of 0.8. love.graphics.newCanvas() is required.

kikito wrote: A couple comments;
...

Code: Select all

local BASE = (...) .. '.'
It is clever and elegant.
Is there an advantage using this approach over the module wrapper approach used here?

https://github.com/vrld/hump/blob/master/vector.lua

This approach seems cleaner and easier to extend.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Quickie [was: Immediate Mode Gui]

Post by kikito »

ncarlson wrote: Is there an advantage using this approach over the module wrapper approach used here?

https://github.com/vrld/hump/blob/master/vector.lua

This approach seems cleaner and easier to extend.
Totally different things. The BASE / (...):match(xxx) thing allow loading files using a pseudo-relative path. The thing at the end of vector is just a table returned from a require.
When I write def I mean function.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Quickie [was: Immediate Mode Gui]

Post by vrld »

ncarlson wrote:I extended the library with a hackish grid/table arranger. (Press "g" to see the grid outline.)
... not to mention the canvas widget. Very clever :3 May I add both to the lib?
kikito wrote:

Code: Select all

local BASE = (...) .. '.'
It is clever and elegant. But also a bit brittle. The code will stop working if someone requires the lib with require 'quickie.init' (small chance, but there is some).
I really like the look of (...) .. '.', but I guess you're right.
kikito wrote:This is slightly more verbose than necessary. The following pattern does the same and it's shorter:

Code: Select all

local core = require((...):match("(.-)[^%.]+$") .. '.core')
Indeed. I will change this.
kikito wrote:What are save_pack and save_unpack doing in core.lua? I don't quite get it.
They allow nil-arguments to be packed into a table. Packing with {...} is problematic with nil arguments:

Code: Select all

> t = {1,2,3,nil,nil,nil,4,5,6}
> for i,k in ipairs(t) do print(i,k) end
1	1
2	2
3	3
On my system unpack(t) yields the expected 1,2,3,nil,nil,nil,4,5,6, but I am not sure if that's true for other computers as well.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: Quickie [was: Immediate Mode Gui]

Post by hryx »

Hey vrld, nice work.

You might already be aware but if you want this to be a musical instrument then the frequency values output from corresponding pitch (X-axis) input should be scaled exponentially instead of linearly. Currently the left half of the pad has the range of one octave while the right half has the range of a perfect fifth.

Assuming:
  • x represents number of pixels on the x axis
  • f(x) finds the frequency
  • You want every 100 pixels of width to represent one octave
  • You want the lowest frequency (far left side of XY pad) to be 110 Hz
Then use the formula:

Code: Select all

f(x) = 110(2^(x/100))
100 pixels to the right would sound 220 Hz, 200 pixels to the right would sound 440 Hz, etc. To generalize:

Code: Select all

output_freq = base_freq * (2^(pixels_from_left / pixels_per_octave))
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Quickie [was: Immediate Mode Gui]

Post by vrld »

Update!

Thanks to MarekkPie, you can now customize the keys that cycle widgets. The default binding is

Code: Select all

gui.core.keyboard.cycle.next = {key = 'tab'}
gui.core.keyboard.cycle.prev = {key = 'tab', 'lshift', 'rshift'}
... which means that 'tab' selects the next widget, while 'tab' + 'lshift' or 'tab' + 'rshift' select the previous widgets. This scheme allows for any two-(but not three [nor four])-key combination to cycle widgets. For example,

Code: Select all

gui.core.keyboard.cycle = {
    prev = {key = ' ', 'a'},
    next = {key = ' ', 'd'},
}
cycles on `space + a' and `space + d'.

Cycle keys take precedence over remaining key actions, so if you set them to 'left' and 'right', you won't be able to move in a textbox anymore.

Updated code is at github: https://github.com/vrld/Quickie
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Quickie [was: Immediate Mode Gui]

Post by MarekkPie »

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

Re: Quickie [was: Immediate Mode Gui]

Post by trubblegum »

When I type in one field, text appears in both fields :death:

Code: Select all

local gui = require('quickie')

function love.load()
	love.graphics.setFont(love.graphics.newFont('georgia.ttf', 10))
end

local state = 'login'

local login = {}
login.username = {text = '', cursor = 0}
login.password = {text = '', cursor = 0}

function love.update(dt)
	if state == 'login' then
		gui.Input(login.username, 16, 16, 256, 16)
		gui.Input(login.password, 288, 16, 256, 16)
		if gui.Button("Log In", 560, 16, 128, 16) then
			-- do stuff
		end
	elseif state == 'world' then
		-- do more stuff
	end
end

function love.draw()
	gui.core.draw()
end

function love.keypressed(key, code)
	gui.core.keyboard.pressed(key, code)
end
User avatar
SiENcE
Party member
Posts: 805
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Quickie [was: Immediate Mode Gui]

Post by SiENcE »

Your samples works for me with current github version.
User avatar
ncarlson
Prole
Posts: 35
Joined: Wed Jul 20, 2011 4:00 pm

Re: Quickie [was: Immediate Mode Gui]

Post by ncarlson »

vrld wrote:
ncarlson wrote:I extended the library with a hackish grid/table arranger. (Press "g" to see the grid outline.)
... not to mention the canvas widget. Very clever :3 May I add both to the lib?
Yeah, dude. Go for it!

Sorry, when you first posted this response, for some reason I read it as "I may add both to the lib". To which I thought, "boy, I hope so".

I'll make a formal fork on github to help work on it. I've been playing around with the idea of a gui for Love for too long now.

He's a button I made about 6 months back. A button!
Attachments
button.love
(245.89 KiB) Downloaded 232 times
User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Quickie [was: Immediate Mode Gui]

Post by trubblegum »

still plugging away, thanks to having got the lib from github.
now trying to make a scrollable set of options, out of a slider and a stack of buttons.

Code: Select all

slider = {value = 1, max = 1, vertical = true, values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}}
function love.update()
	slider.max = #slider.values - 16
	gui.Slider(slider, client.width - 32, 16, 16, 256, false)
	
	i = math.ceil(slider.value)
	last = i + 16
	y = 1
	while i <= last do
		if gui.Button(slider.values[i], 16, 16 * y, love.graphics.getWidth() - 64, 16) then
			
			print('selected '..slider.values[i])
			
		end
		i = i + 1
		y = y + 1
	end
end
seems pretty straightforward, but when i slide down to the bottom, i get :

Code: Select all

quickie//style-default.lua:19: bad argument #1 to 'getWidth' (string exected, got nil)
note that i'm using the slider with vertical = true
is it me? or is this an issue?
Last edited by trubblegum on Mon Feb 27, 2012 8:29 am, edited 2 times in total.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest