PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 118ms app.codeStats 0ms

/script_binding/lua/demo_icon_view.lua

http://ftk.googlecode.com/
Lua | 66 lines | 50 code | 16 blank | 0 comment | 2 complexity | dc07ae7bd0e9c0ffbdd440d974b300d6 MD5 | raw file
 1function OnQuit(button)
 2	Ftk.Quit()
 3
 4	return RET_OK
 5end
 6
 7function OnMore(button)
 8	local icon_view = button:Toplevel():Lookup(100);
 9	local item=FtkIconViewItem.Create()
10	item.icon = FtkTheme.LoadImage(Ftk.DefaultTheme(), "flag-32.png")
11
12	for i=1, 10 do
13		item.text = "item" .. tostring(i)
14		icon_view:Add(item)
15	end
16
17	item.icon:Unref()
18	item=nil
19
20	return RET_OK
21end
22
23function OnItemClicked(item)
24	print("OnItemClicked: " .. item.text)
25	return RET_OK
26end
27
28function AppInit()
29	win=FtkAppWindow.Create()
30	win:SetText("Demo icon view")
31	win:SetAttr(FTK_ATTR_QUIT_WHEN_CLOSE)
32
33	width=win:Width()
34	height=win:Height()
35
36	button=FtkButton.Create(win, 10, 0, width/3-10, 60)
37	button:SetText("More")
38	button:SetClickedListener("OnMore")
39
40	button=FtkButton.Create(win, 2*width/3, 0, width/3-10, 60)
41	button:SetText("Quit")
42	button:SetClickedListener("OnQuit")
43
44	item=FtkIconViewItem.Create()
45	item.icon = FtkTheme.LoadImage(Ftk.DefaultTheme(), "flag-32.png")
46	
47	icon_view = FtkIconView.Create(win, 5, 70, width-10, height-80)
48	icon_view:SetId(100);
49	icon_view:SetClickedListener("OnItemClicked")
50	for i=1, 10 do
51		item.text = "item" .. tostring(i)
52		icon_view:Add(item)
53	end
54	item.icon:Unref()
55	item=nil
56
57	win:SetFocus(button)
58	win:ShowAll(1)
59
60	return 1
61end
62
63Ftk.Init(1, {"iconview"})
64AppInit()
65Ftk.Run()
66