Using switch, first draft to use switches.

This commit is contained in:
Pcornat 2026-01-25 22:36:35 +01:00
commit 87d2db2243
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
3 changed files with 70 additions and 2 deletions

View file

@ -1,8 +1,14 @@
#ifndef LEARNGTK4_APP_WIN_2_BACK_HPP
#define LEARNGTK4_APP_WIN_2_BACK_HPP
#include <gtkmm/application.h>
#include <array>
#include <glibmm/refptr.h>
#include <gtkmm/application.h>
#include <billy_objects.hpp>
#include <character_sheet.hpp>
#include <gtkmm/switch.h>
namespace learn_gtkmm4 {
class HelloWorld;
@ -28,8 +34,23 @@ namespace gui_to_app {
void on_activate() final;
private:
struct SwitchSignalHelper {
AppWin2Back &app;
const character::billyEnums obj;
Gtk::Switch *switch_{ nullptr };
[[nodiscard]] bool signal_handler(const bool flag) const noexcept {
switch_->set_state(app.switch_signal_handler(flag, obj));
return true;
}
};
friend struct SwitchSignalHelper;
void on_quit() noexcept;
bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept;
Glib::RefPtr<Gtk::Builder> app_builder;
learn_gtkmm4::HelloWorld *main_window{ nullptr };
Gtk::Switch *sword_switch{ nullptr };
@ -46,6 +67,26 @@ namespace gui_to_app {
Gtk::Switch *dagger_switch{ nullptr };
Gtk::Switch *rock_kit_switch{ nullptr };
Gtk::Switch *sack_switch{ nullptr };
std::array<SwitchSignalHelper, 12> signal_handlers{
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Sword },
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Lance },
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Morgenstern },
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Bow },
SwitchSignalHelper{ .app = *this, .obj = character::equipments::Chainmail },
SwitchSignalHelper{ .app = *this, .obj = character::equipments::CookingPot },
SwitchSignalHelper{ .app = *this, .obj = character::equipments::PamphletTourist },
SwitchSignalHelper{ .app = *this, .obj = character::equipments::MedicKit },
SwitchSignalHelper{ .app = *this, .obj = character::tools::Fourche },
SwitchSignalHelper{ .app = *this, .obj = character::tools::Dagger },
SwitchSignalHelper{ .app = *this, .obj = character::tools::RockClimbingKit },
SwitchSignalHelper{ .app = *this, .obj = character::tools::SackOfGrain },
};
character::BillyObjects gestionnaire{};
character::CharacterSheet sheet{};
};
} // gui_to_app