Fill listbox

From Vendetta Lua
Revision as of 18:54, 20 November 2010 by Lemming (Talk | contribs) (Reverted edits by Otutytaqo (Talk) to last version by Chefkoch)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

setup_cb

Definition:
setup_cb(int index, table itemlist, userdata subdlg) -> nil

Description:
Function initializes a list item in a list

Arguments:
index position within itemlist
itemlist table of iteminfo
subdialog an itemlist dialog

Example

-- a very crude item list with static data
-- to be useful the action callback for c would handle highlighting and activation of items
 
-- build item list
local items = {}
-- title item
table.insert(items, {desc="test"})
table.insert(items, {name="name1", desc="item1", quantity=2, price=10})
table.insert(items, {name="name2", desc="item2", price=11})
table.insert(items, {desc="test2"})
table.insert(items, {name="name3", desc="item3", price=13})
 
local c = iup.itemlisttemplate{control="yes", size="400x300"}
local d = iup.dialog{c, topmost="yes"}
 
-- function called for each itemlist item
local function setup_cb(index, item, subdlg)
	if item.price then
		subdlg:SetDesc(item.desc, false)
		subdlg:SetIcon("images/icon_addon_empty.png")
	else
		-- item is category item
		-- senter description
		subdlg:SetDesc(item.desc, true)
		subdlg:SetIcon()
	end
 
	-- intialize some more fields
	subdlg:SetName(item.name)
	subdlg:SetQuantity(item.quantity)
	subdlg:SetPrice(item.price)
end
 
d:show()
 
-- fill the list
fill_listbox(c, items, 1, setup_cb, true, true)