LoveUI for Love 0.5.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: LoveUI... has button, Textfield, scrollVIew

Post by TsT »

appleide wrote: function LoveUI.getVersion()
return "03062009unstable2300" -- release date and version of LoveUI library
end
Not bad but I suggest you to have a :

function LoveUI.getVersion()
local release = "unstable" -- stable/unstable/testing/what-you-want
local revision = 20090603.2300 -- with YYYYMMDD.HHMM very usefull to compare as number
return release, revision -- release date and version of LoveUI library
end[/quote]

So you can easily try

Code: Select all

local release, revision = LoveUI.getVersion()
if release == "unstable" and revision >= 20090600 then
...
end
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: LoveUI... has button, Textfield, scrollVIew

Post by appleide »

Okay, I've done it like that, just wait for the next revision ;)

EDIT:.

btw, example TableView code for the tableView.
Create data object and put it into create TableView statement. the data object really only needs the functions, and 'self' is the tableView, not the data object itself. I've sourced my data from arrays but you can do it from anywhere else.
Looks like this for now:

Code: Select all

--TABLEVIEW
local tData={};
tData.cells={}; --used to cache cells
tData.headers={{"IP Address", 100}, {"Game Type", 100}, {"# Players", 100}}; -- column info, col name and col width
tData.mpgames={ --table data
		{"192.168.0.2", "Melee", "2"},
		{"192.168.0.5", "Death Match", "5"},
		{"192.168.0.13", "Custom", "8"},
		{"192.168.0.7", "Default", "3"},
		{"192.168.0.9", "Melee", "2"},
		{"192.168.0.3", "Default", "8"},
		{"192.168.0.8", "Death Match", "4"}
	}
function tData:attributesForColumn(columnIndex)
	return unpack(tData.headers[columnIndex]); --return headerName, columnWidth
end

function tData:viewForCell(rowIndex, columnIndex)
	--tableview queries a view at row, column
	tData.cells[rowIndex]=tData.cells[rowIndex] or {};
	tData.cells[rowIndex][columnIndex]=tData.cells[rowIndex][columnIndex] or 
		LoveUI.TableViewCell:new(); --caching cells so they dont need to be recreated everytime reload Data is called.
		
	tData.cells[rowIndex][columnIndex].value=tData.mpgames[rowIndex][columnIndex];
	
	return tData.cells[rowIndex][columnIndex]; --returns a cell
end

function tData:numberOfRows ()
	--tableview queries the number of rows in table.
	return #tData.mpgames 
end

function tData:numberOfColumns ()
	--tableview queries the number of columns in table.
	return #tData.headers
end

function tData:sortColumn (columnIndex, ascending)
	--tableview requests column to be sorted ; implement sort here
	
		table.sort(tData.mpgames, function(rowA,rowB) 
			if (ascending) then
				return rowA[columnIndex] < rowB[columnIndex]
			else
				return rowA[columnIndex] > rowB[columnIndex]
			end
		end)
		
	self:reloadData()
end
local aTableView=LoveUI.TableView:new(LoveUI.Rect:new(400, 300, 250, 250), tData) --make tableView with data object


--add the views to context
aContext:addSubview(aTableView);

User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: LoveUI... has button, Textfield, scrollVIew

Post by appleide »

TableView mostly complete. What else to add to it?

EDIT: When table is re-sorted by clicking one of the column Headers, the selection used to stay in the same row while the data changed. I got around this by changing selection so that the first column's data remains the same. It's a cheap hack because it assumes the first column is a primary key. What do you think? I could check every data row? Or just set selection to none?

There's also no multiple selection, since I m assuming no one needs it? It wouldn't be as easy to implement since I have to detect mouse drags in different views update loops. (maybe 10-40x more time to implement than single selection)
Attachments
Picture 2.png
Picture 2.png (20.65 KiB) Viewed 3334 times
LoveUI(unstable).love
(83.85 KiB) Downloaded 143 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LoveUI... has button, Textfield, scrollVIew

Post by Robin »

appleide wrote:What do you think? I could check every data row? Or just set selection to none?
How about adding Selection as a "virtual column" while sorting? That way, selection is associated to the data all along, and will also work perfectly with a multiple selection-feature.
Help us help you: attach a .love.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: LoveUI... has button, Textfield, scrollVIew

Post by appleide »

Robin wrote:
appleide wrote:What do you think? I could check every data row? Or just set selection to none?
How about adding Selection as a "virtual column" while sorting? That way, selection is associated to the data all along, and will also work perfectly with a multiple selection-feature.
You mean like P_id? it'll be done.

datasource function changed to:

Code: Select all


function tData:attributesForColumn(columnIndex)
	return unpack(tData.headers[columnIndex]); --return headerName, columnWidth, columnHidden
end

return true for third value to hide the column, so the idea is you make the first column unique IDs, but you might not want them visible, so return hidden=true for that column. Side effect: you can optionally hide any number of other columns too.
Attachments
LoveUI(unstable).love
unstable revision 20090604.0017
(83.9 KiB) Downloaded 153 times
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: LoveUI... has button, Textfield, scrollVIew

Post by Sparx »

Sorry that I reply this late since I was very interested in this feature.
It looks absolutely perfect!
One question on the demo(i didn't look into the code yet):
Is the gap on right side of the table wanted?
Which just leads me to a new idea: How about changing the width of a column by draging the bar in between the columns(to certain minimum).

And what happens if the content of the table is more than to be shown inside the box, is there a scrollbar to?

[EDIT]
And just had another idea: Im looking for a menu to set the keys for movement etc.. A box, if you klick it the value is deleted and it waits for a user input.
[/EDIT]
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: LoveUI... has button, Textfield, scrollVIew

Post by Sparx »

I integrated the tableiew into my project. I change the tabledata and want it to refresh afterwards like reload table data... I don't know how to do this(i don't get it with the methods here) If i klick to sort the table my data appears because the sorting also refreshes the content....
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: LoveUI... has button, Textfield, scrollVIew

Post by appleide »

Try calling aTableView:reloadData() every time you change the data; That should solve it.

The gap on the right side of the table is only because I made the table too big so it had to be filled with empty space.
Dragging the column to change the width isn't exactly a new idea. ;) I'll look into it but I don't think it's easy.
When the content exceeds the table there is a scrollbar.

For the box idea.... If I programmed Textfields to have a onfocus event you could set the behaviour yourself...... But I didn't because there was so much to do (i.e I was lazy). Keep an eye out for the next version. :)

I also need to find a way to make the performance of the tableview much better........ When you have over 50 rows it starts to slow down.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LoveUI... has button, Textfield, scrollVIew

Post by Robin »

Hm... I thought: "Let's implement an onfocus event for Textfields. It doesn't seem that complex, and how hard can it be?"

But I got a little confused by the complex internal API :shock:. I don't even know what file to edit. (LoveUITextfield.lua? LoveUITextfieldCell.lua? LoveUIMagicFairies.lua?)

EDIT: Am I right the event should be called in LoveUI.Textfield:becomeFirstResponder()?
Help us help you: attach a .love.
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: LoveUI... has button, Textfield, scrollVIew

Post by Sparx »

Tried that before but now i found out that the function calling the reload was initialized before aTableView was loaded so...
Post Reply

Who is online

Users browsing this forum: No registered users and 222 guests