-
Notifications
You must be signed in to change notification settings - Fork 15
/
Timer.cpp
56 lines (49 loc) · 1.45 KB
/
Timer.cpp
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
#include <iomanip>
#include <gtkmm.h>
using namespace Glib;
using namespace Gtk;
class Form : public Window {
public:
Form() {
add(scrolledWindow);
scrolledWindow.add(fixed);
label.set_text(ustring::format(std::fixed, std::setprecision(1), (double)counter / 10));
label.override_color(Gdk::RGBA("#1E90FF"));
Pango::FontDescription textFont("Arial");
textFont.set_size(48 * PANGO_SCALE);
textFont.set_style(Pango::Style::STYLE_ITALIC);
textFont.set_weight(Pango::Weight::WEIGHT_BOLD);
label.override_font(textFont);
fixed.add(label);
fixed.move(label, 10, 10);
button.set_label("Start");
fixed.add(button);
fixed.move(button, 10, 90);
button.signal_button_release_event().connect([&](GdkEventButton* event) {
enableTimer = !enableTimer;
button.set_label(enableTimer ? "Stop" : "Start");
if (enableTimer) {
signal_timeout().connect([&] {
label.set_text(ustring::format(std::fixed, std::setprecision(1), (double)++counter / 10));
return enableTimer;
}, 100);
}
return true;
});
set_title("Timer example");
resize(230, 130);
show_all();
}
private:
Fixed fixed;
ScrolledWindow scrolledWindow;
Label label;
Button button;
bool enableTimer = false;
int counter = 0;
};
int main(int argc, char* argv[]) {
RefPtr<Application> application = Application::create(argc, argv);
Form form;
return application->run(form);
}