It completely works
This commit is contained in:
parent
ad879dd7a3
commit
cea2c1296f
8 changed files with 698 additions and 58 deletions
61
app_win_2_back.cpp
Normal file
61
app_win_2_back.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "app_win_2_back.hpp"
|
||||
#include "hello_world.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace gui_to_app {
|
||||
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) {
|
||||
Glib::set_application_name("Billy's character sheet");
|
||||
}
|
||||
|
||||
void AppWin2Back::on_startup() {
|
||||
Application::on_startup();
|
||||
const auto menu_bar = []() -> Glib::RefPtr<Gio::Menu> {
|
||||
try {
|
||||
const auto builder = Gtk::Builder::create_from_file("menu_bar.ui");
|
||||
return builder->get_object<Gio::Menu>("menu");
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
}();
|
||||
if (!menu_bar) {
|
||||
std::cerr << "Error occured while loading menu bar's.\n";
|
||||
} else {
|
||||
set_menubar(menu_bar);
|
||||
add_action("quit", sigc::mem_fun(*this, &AppWin2Back::quit));
|
||||
set_accel_for_action("app.quit", "<Ctrl>q");
|
||||
}
|
||||
}
|
||||
|
||||
Glib::RefPtr<AppWin2Back> AppWin2Back::create() {
|
||||
return Glib::make_refptr_for_instance(new AppWin2Back());
|
||||
}
|
||||
|
||||
void AppWin2Back::on_activate() {
|
||||
Application::on_activate();
|
||||
|
||||
const auto app_builder = [this]() -> Glib::RefPtr<Gtk::Builder> {
|
||||
try {
|
||||
return Gtk::Builder::create_from_file("window_ui.ui");
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
quit();
|
||||
return nullptr;
|
||||
}
|
||||
}();
|
||||
if (!app_builder) {
|
||||
std::cerr << "Error while loading UI.\n";
|
||||
quit();
|
||||
return;
|
||||
}
|
||||
main_window = Gtk::Builder::get_widget_derived<learn_gtkmm4::HelloWorld>(app_builder, "main_window");
|
||||
if (main_window != nullptr) {
|
||||
add_window(*main_window);
|
||||
main_window->set_show_menubar(true);
|
||||
main_window->set_visible(true);
|
||||
} else {
|
||||
quit();
|
||||
}
|
||||
}
|
||||
|
||||
} // gui_to_app
|
Loading…
Add table
Add a link
Reference in a new issue