diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ec7d79..735fca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index aa743ed..1feca51 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -1,10 +1,16 @@ #include "app_win_2_back.hpp" #include "hello_world.hpp" + #include #include #include +#include + 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 { + app_builder = [this] -> Glib::RefPtr { 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("rock_kit_switch"); sack_switch = app_builder->get_widget("sack_switch"); - const auto test_result = [this]() -> std::vector { + const auto test_result = [this] -> std::vector { 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 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 >( + 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 diff --git a/main.cpp b/main.cpp index fe0d3eb..d267240 100644 --- a/main.cpp +++ b/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); }