File: DemoCustomList.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (81 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module DemoCustomList;

import CustomList;

import gio.Application : GioApplication = Application;
import glib.RandG;
import gtk.Application;
import gtk.ApplicationWindow;
import gtk.CellRendererText;
import gtk.ListStore;
import gtk.ScrolledWindow;
import gtk.TreeView;
import gtk.TreeViewColumn;

class CustomListWindow : ApplicationWindow
{
	this(Application application)
	{
		super(application);
		setTitle("GtkD - Custom TreeModel");
		setDefaultSize(300, 400);
		
		ScrolledWindow scrollwin = new ScrolledWindow();
		TreeView view = createViewAndModel();

		scrollwin.add(view);
		add(scrollwin);

		showAll();
	}

	TreeView createViewAndModel()
	{
		TreeViewColumn   col;
		CellRendererText renderer;
		CustomList       customlist;
		TreeView         view;

		customlist = new CustomList();
		fillModel(customlist);
		
		view = new TreeView(customlist);
		
		col = new TreeViewColumn();
		renderer  = new CellRendererText();
		col.packStart(renderer, true);
		col.addAttribute(renderer, "text", CustomListColumn.Name);
		col.setTitle("Name");
		view.appendColumn(col);

		col = new TreeViewColumn();
		renderer  = new CellRendererText();
		col.packStart(renderer, true);
		col.addAttribute(renderer, "text", CustomListColumn.YearBorn);
		col.setTitle("Year Born");
		view.appendColumn(col);

		return view;
	}

	void fillModel (CustomList customlist)
	{
		string[]  firstnames = [ "Joe", "Jane", "William", "Hannibal", "Timothy", "Gargamel" ];
		string[]  surnames   = [ "Grokowich", "Twitch", "Borheimer", "Bork" ];

		foreach (sname; surnames)
		{
			foreach (fname; firstnames)
			{
				customlist.appendRecord(fname ~" "~ sname, 1900 + (RandG.randomInt() % 100));
			}
		}
	}
}

int main (string[] args)
{
	auto application = new Application("org.gtkd.demo.customlist", GApplicationFlags.FLAGS_NONE);
	application.addOnActivate(delegate void(GioApplication app) { new CustomListWindow(application); });
	return application.run(args);
}