forked from gerito1/vala-gtk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressbar.vala
61 lines (46 loc) · 1.31 KB
/
progressbar.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
/*
* A ProgressBar is used to indicate the amount of a long-running progress that
* has completed.
*/
using Gtk;
using GLib;
public class Example : Window
{
private ProgressBar progressbar;
private CheckButton checkbutton;
public Example()
{
this.title = "ProgressBar";
this.destroy.connect(Gtk.main_quit);
var grid = new Grid();
this.add(grid);
progressbar = new ProgressBar();
progressbar.set_hexpand(true);
grid.attach(progressbar, 0, 0, 1, 1);
checkbutton = new CheckButton.with_label("Show Text");
checkbutton.toggled.connect(on_show_text_toggled);
grid.attach(checkbutton, 0, 1, 1, 1);
GLib.Timeout.add(500, progressbar_fill);
}
private bool progressbar_fill()
{
double amount = progressbar.get_fraction();
if (amount < 1.0)
progressbar.set_fraction(amount + 0.1);
else
progressbar.set_fraction(0.0);
return true;
}
private void on_show_text_toggled(Gtk.ToggleButton checkbutton)
{
progressbar.set_show_text(checkbutton.get_active());
}
public static int main(string[] args)
{
Gtk.init(ref args);
var window = new Example();
window.show_all();
Gtk.main();
return 0;
}
}