Modernize code
This commit is contained in:
parent
9f479dc808
commit
a67eb0d0b5
3 changed files with 24 additions and 23 deletions
|
|
@ -79,8 +79,8 @@ add_executable(LearnGtk4 main.cpp
|
|||
app_win_2_back.hpp
|
||||
)
|
||||
|
||||
set_target_properties(LearnGtk4 assimp spdlog_header_only PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
set_target_properties(LearnGtk4 spdlog_header_only PROPERTIES
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS OFF
|
||||
INTERPROCEDURAL_OPTIMIZATION ON
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
#include "app_win_2_back.hpp"
|
||||
#include "hello_world.hpp"
|
||||
|
||||
#include <glibmm/miscutils.h>
|
||||
#include <gtkmm/switch.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <ranges>
|
||||
|
||||
namespace gui_to_app {
|
||||
namespace ranges = std::ranges;
|
||||
namespace views = std::views;
|
||||
|
||||
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) {
|
||||
Glib::set_application_name("Billy's character sheet");
|
||||
}
|
||||
|
|
@ -36,7 +42,7 @@ namespace gui_to_app {
|
|||
void AppWin2Back::on_activate() {
|
||||
Application::on_activate();
|
||||
|
||||
app_builder = [this]() -> Glib::RefPtr<Gtk::Builder> {
|
||||
app_builder = [this] -> Glib::RefPtr<Gtk::Builder> {
|
||||
try {
|
||||
return Gtk::Builder::create_from_file("window_ui.ui");
|
||||
} catch (const std::exception &e) {
|
||||
|
|
@ -73,7 +79,7 @@ namespace gui_to_app {
|
|||
rock_kit_switch = app_builder->get_widget<Gtk::Switch>("rock_kit_switch");
|
||||
sack_switch = app_builder->get_widget<Gtk::Switch>("sack_switch");
|
||||
|
||||
const auto test_result = [this]() -> std::vector<const char *> {
|
||||
const auto test_result = [this] -> std::vector<const char *> {
|
||||
const std::array test_ptrs{
|
||||
std::pair{ "sword_switch", sword_switch == nullptr },
|
||||
std::pair{ "lance_switch", lance_switch == nullptr },
|
||||
|
|
@ -88,16 +94,12 @@ namespace gui_to_app {
|
|||
std::pair{ "rock_kit_switch", rock_kit_switch == nullptr },
|
||||
std::pair{ "sack_switch", sack_switch == nullptr },
|
||||
};
|
||||
std::vector<const char *> local_test_result;
|
||||
local_test_result.reserve(test_ptrs.size());
|
||||
std::for_each(test_ptrs.cbegin(),
|
||||
test_ptrs.cend(),
|
||||
[&local_test_result](const auto &a) {
|
||||
if (a.second) {
|
||||
local_test_result.emplace_back(a.first);
|
||||
}
|
||||
});
|
||||
return local_test_result;
|
||||
|
||||
return ranges::to<std::vector<const char *> >(
|
||||
test_ptrs
|
||||
| views::filter([](const auto &a) { return a.second; })
|
||||
| views::keys
|
||||
);
|
||||
}();
|
||||
if (!test_result.empty()) {
|
||||
spdlog::critical("Error occurred, at least one switch is not available. See logs below");
|
||||
|
|
@ -107,16 +109,15 @@ namespace gui_to_app {
|
|||
on_quit();
|
||||
return;
|
||||
}
|
||||
// TODO: interaction avec la CharacterSheet
|
||||
}
|
||||
|
||||
void AppWin2Back::on_quit() noexcept {
|
||||
auto windows = get_windows();
|
||||
for (auto *window: windows) {
|
||||
if (window != nullptr) {
|
||||
window->set_visible(false);
|
||||
delete window;
|
||||
}
|
||||
}
|
||||
ranges::for_each(get_windows() | views::filter([](const auto windows) { return windows != nullptr; }),
|
||||
[](auto *window) {
|
||||
window->set_visible(false);
|
||||
delete window;
|
||||
});
|
||||
quit();
|
||||
}
|
||||
} // gui_to_app
|
||||
|
|
|
|||
4
main.cpp
4
main.cpp
|
|
@ -1,6 +1,6 @@
|
|||
#include "app_win_2_back.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
auto app = gui_to_app::AppWin2Back::create();
|
||||
int main(const int argc, char *argv[]) {
|
||||
const auto app = gui_to_app::AppWin2Back::create();
|
||||
return app->run(argc, argv);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue