This repository has been archived by the owner on Jan 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy.vala
113 lines (88 loc) · 2.1 KB
/
easy.vala
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4:
const int N = 30000000;
class Data : GLib.Object
{
public int index;
public Data (int i) { index = i; }
}
class Row : Gtk.ListBoxRow
{
private Gtk.Label label;
public Row ()
{
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
label = new Gtk.Label ("Foobar \\o/");
label.ellipsize = Pango.EllipsizeMode.END;
label.hexpand = true;
label.halign = Gtk.Align.START;
box.add (label);
var button = new Gtk.Button.with_label ("Click Me");
box.add (button);
box.margin = 6;
this.add (box);
}
public void assign (Data d)
{
this.label.label = "\\o/ %d".printf (d.index);
}
}
class Model : GLib.ListModel, GLib.Object
{
private Data[] data;
public Model (int count)
{
this.data = new Data[count];
}
public GLib.Type get_item_type ()
{
return typeof (Data);
}
public uint get_n_items ()
{
return data.length;
}
public GLib.Object? get_item (uint index)
{
return this.data[index];
}
public new void set (int index, Data data)
{
this.data[index] = data;
}
}
void main (string[] args)
{
Gtk.init (ref args);
var window = new Gtk.Window ();
var list = new ModelListBox ();
var model = new Model (N);
var scroller = new Gtk.ScrolledWindow (null, null);
try {
var provider = new Gtk.CssProvider ();
provider.load_from_data (".list-row { border-bottom: 1px solid alpha(grey, 0.3);}",-1);
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
error (e.message);
}
for (int i = 0; i < N; i ++) {
// dummy
model.set (i, new Data (i));
}
list.set_model (model);
list.fill_func = (item, old_widget) => {
Row? row = null;
if (old_widget != null) row = old_widget as Row;
else row = new Row ();
row.assign ((Data)item);
row.show_all ();
return row;
};
scroller.add (list);
scroller.margin_bottom = 40;
window.add (scroller);
window.resize (400, 400);
window.show_all ();
Gtk.main ();
}