This repository was 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
Expand file tree
/
Copy pathoverestimate.vala
More file actions
131 lines (96 loc) · 2.66 KB
/
overestimate.vala
File metadata and controls
131 lines (96 loc) · 2.66 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4:
/*
*
* Test case for an overestimate of the list size at the bottom.
*
*/
class Data : GLib.Object {
public string str;
public uint index;
}
class Row : Gtk.ListBoxRow {
private Gtk.Label label;
public Row () {
this.label = new Gtk.Label ("");
this.label.margin = 6;
this.add (label);
}
public void assign (Data d) {
this.label.label = d.str;
}
}
void main (string[] args)
{
Gtk.init (ref args);
var window = new Gtk.Window ();
var scroller = new Gtk.ScrolledWindow (null, null);
var list = new ModelListBox ();
var model = new GLib.ListStore (typeof (Data));
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 (uint i = 0; i < 400; i ++) {
var d = new Data ();
d.str = "Foobar %u".printf (i);
d.index = i;
model.append (d);
}
list.fill_func = (item, old) => {
Row row;
Data data = (Data) item;
if (old != null) row = old as Row;
else row = new Row ();
assert (item != null);
row.assign (data);
//if (data.index < 3)
if (data.index > 10)
row.set_size_request (-1, 100);
else
row.set_size_request (-1, -1);
row.show_all ();
return row;
};
list.set_model (model);
var bbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
bbox.hexpand = true;
bbox.get_style_context ().add_class ("linked");
var top_btn = new Gtk.Button.with_label ("Top");
top_btn.clicked.connect (() => {
scroller.get_vadjustment ().value = 0.0;
});
bbox.add (top_btn);
var up_btn = new Gtk.Button.with_label ("up");
up_btn.clicked.connect (() => {
scroller.get_vadjustment ().value -= 1.0;
});
bbox.add (up_btn);
var down_btn = new Gtk.Button.with_label ("down");
down_btn.clicked.connect (() => {
scroller.get_vadjustment ().value += 1.0;
});
bbox.add (down_btn);
var bottom_btn = new Gtk.Button.with_label ("Bottom");
bottom_btn.clicked.connect (() => {
var vadj = scroller.get_vadjustment ();
vadj.value = vadj.upper - vadj.page_size;
});
bbox.add (bottom_btn);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
bbox.margin_bottom = 6;
bbox.halign = Gtk.Align.CENTER;
scroller.vexpand = true;
scroller.add (list);
box.add (scroller);
box.add (bbox);
window.add (box);
window.resize (400, 300);
window.delete_event.connect (() => { Gtk.main_quit (); return true;});
window.show_all ();
Gtk.main ();
}