Add simple gtkmm3 code
This commit is contained in:
55
src/main.cpp
55
src/main.cpp
@@ -1,19 +1,50 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtkmm.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void end_program(GtkWidget *wid, gpointer ptr)
|
class CloseButton : public Gtk::Button
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
private:
|
||||||
|
void on_button_clicked();
|
||||||
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
|
public:
|
||||||
|
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app);
|
||||||
|
};
|
||||||
|
|
||||||
|
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app)
|
||||||
|
{
|
||||||
|
this->app = app;
|
||||||
|
|
||||||
|
set_label(label);
|
||||||
|
|
||||||
|
signal_clicked().connect(sigc::mem_fun(*this, &CloseButton::on_button_clicked));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButton::on_button_clicked()
|
||||||
|
{
|
||||||
|
this->app.get()->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyWindow : public Gtk::Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyWindow();
|
||||||
|
};
|
||||||
|
|
||||||
|
MyWindow::MyWindow()
|
||||||
|
{
|
||||||
|
set_title("Basic application");
|
||||||
|
set_default_size(200, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
gtk_init(&argc, &argv);
|
auto app = Gtk::Application::create("org.gtkmm.examples.base");
|
||||||
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
MyWindow window;
|
||||||
GtkWidget *btn = gtk_button_new_with_label("Close Window");
|
|
||||||
g_signal_connect(btn, "clicked", G_CALLBACK(end_program), NULL);
|
CloseButton button("Close", app);
|
||||||
g_signal_connect(win, "delete_event", G_CALLBACK(end_program), NULL);
|
window.add(button);
|
||||||
gtk_container_add(GTK_CONTAINER(win), btn);
|
window.show_all();
|
||||||
gtk_widget_show_all(win);
|
|
||||||
gtk_main();
|
return app->run(window);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user