Page 2 of 8

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 09, 2012 4:26 pm
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.

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 09, 2012 5:04 pm
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.

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 09, 2012 9:59 pm
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.

Re: Quickie [was: Immediate Mode Gui]

Posted: Sat Feb 11, 2012 7:11 am
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))

Re: Quickie [was: Immediate Mode Gui]

Posted: Wed Feb 22, 2012 11:02 pm
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

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 23, 2012 1:37 am
by MarekkPie
*pops collar*

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 23, 2012 3:39 pm
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

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 23, 2012 4:42 pm
by SiENcE
Your samples works for me with current github version.

Re: Quickie [was: Immediate Mode Gui]

Posted: Thu Feb 23, 2012 5:24 pm
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!

Re: Quickie [was: Immediate Mode Gui]

Posted: Sun Feb 26, 2012 11:04 pm
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?