Difference between revisions of "Fill accomlistbox"

From Vendetta Lua
Jump to: navigation, search
(New page: == Example == <source lang="lua"> -- a simple accomplishment list with static data -- TODO: figure out how to get rid of the white boxes -- build item list local items = {} -- title item...)
 
 
Line 1: Line 1:
 +
== itemlist ==
 +
'''Description:''' <br>
 +
Table that describes an accomplishment item or category title. The title field determines if the item is a title or accomplishment
 +
<br><br>
 +
'''Elements:'''<br>
 +
'''title''' category title or nil<br>
 +
<br><br>
 +
 +
== setup_cb ==
 +
'''Definition:'''<br>
 +
setup_cb(int index, table itemlist, userdata subdlg, function click_cb) -> int newindex
 +
<br><br>
 +
'''Description:''' <br>
 +
Function initializes a list item in an accomplishment list
 +
<br><br>
 +
'''Arguments:'''<br>
 +
'''index''' position within itemlist<br>
 +
'''itemlist''' see [[Fill_accomlistbox#itemlist|itemlist]]<br>
 +
'''subdialog''' an itemlist dialog<br>
 +
'''click_cb''' function called after clicking on '''subdialog'''
 +
<br><br>
 +
 
== Example ==
 
== Example ==
  

Latest revision as of 19:24, 23 January 2009

itemlist

Description:
Table that describes an accomplishment item or category title. The title field determines if the item is a title or accomplishment

Elements:
title category title or nil


setup_cb

Definition:
setup_cb(int index, table itemlist, userdata subdlg, function click_cb) -> int newindex

Description:
Function initializes a list item in an accomplishment list

Arguments:
index position within itemlist
itemlist see itemlist
subdialog an itemlist dialog
click_cb function called after clicking on subdialog

Example

-- a simple accomplishment list with static data
-- TODO: figure out how to get rid of the white boxes
 
-- build item list
local items = {}
-- title item
table.insert(items, {title="test"})
-- accomplishment items
-- index is an accomplishment index
table.insert(items, {index=1})
table.insert(items, {index=2})
table.insert(items, {index=3})
 
table.insert(items, {title="test2"})
table.insert(items, {index=4})
table.insert(items, {index=5})
 
local c = iup.itemlisttemplate{control="yes", size="400x300"}
local d = iup.dialog{c, topmost="yes"}
 
-- function called for each row
local function setup_cb(index, itemlist, subdlg)
	local item = itemlist[index]
 
	-- item is category item
	-- there can only be one per row
	-- add it and return incremented index
	if item.title then
		subdlg:SetTitle(item.title)
		return index + 1
	end
 
	-- add icons till the row is filled, end of itemlist
	-- is reached or the item is a new category
	for i=1,MAX_ACCOMICON2_COLUMNS do
		if index > #itemlist then
			break
		end
 
		local item = itemlist[index]
		if item.title then
			-- got next category
			return index
		else
			-- add an icon
			subdlg:SetIcon(i, "images/icon_addon_empty.png", "0 0 1 1", "32x32", nil, "Accomplishment "..tostring(item.index)) 
		end
		index = index + 1
	end
	-- return new index
	return index
end
 
d:show()
 
-- fill the list
fill_accomlistbox(c, items, setup_cb)