Compare commits

..

No commits in common. "93eb59b9182b22a3f3aaf93964645776153f8141" and "a54d1f7e984b52d437a4123ac267a31c121242e7" have entirely different histories.

3 changed files with 23 additions and 103 deletions

View file

@ -50,8 +50,6 @@ namespace gui_to_app {
if (!app.insert_obj(obj)) { if (!app.insert_obj(obj)) {
on_stack = true; on_stack = true;
switch_->set_active(false); switch_->set_active(false);
} else {
app.update_labels();
} }
} else { } else {
if (!app.erase_obj(obj)) { if (!app.erase_obj(obj)) {
@ -61,8 +59,6 @@ namespace gui_to_app {
"Erasing object {} was not successful", "Erasing object {} was not successful",
character::BillyObjects::billy_object_to_string(obj).data() character::BillyObjects::billy_object_to_string(obj).data()
); );
} else {
app.update_labels();
} }
} }
} }
@ -169,24 +165,10 @@ namespace gui_to_app {
return; return;
} }
debug_button = app_builder->get_widget<Gtk::Button>("debug_button"); debug_button = app_builder->get_widget<Gtk::Button>("debug_button");
hab_labels = CaracInterface<Gtk::Label>{ hab_base = app_builder->get_widget<Gtk::Label>("habilete_label_base");
{ hab_carac = app_builder->get_widget<Gtk::Label>("habilete_label_carac");
"habilete_label_base", hab_mat = app_builder->get_widget<Gtk::Label>("habilete_label_materiel");
"habilete_label_carac", hab_total = app_builder->get_widget<Gtk::Label>("habilete_label_total");
"habilete_label_materiel",
"habilete_label_total"
},
app_builder
};
endu_labels = CaracInterface<Gtk::Label>{
{
"endurance_label_base",
"endurance_label_carac",
"endurance_label_materiel",
"endurance_label_total"
},
app_builder
};
debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false); debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false);
} }
@ -200,52 +182,17 @@ namespace gui_to_app {
quit(); quit();
} }
bool AppWin2Back::switch_signal_handler(const bool flag, const character::billyEnums &obj) noexcept {
return flag ? gestionnaire.insert_object(sheet, obj) : !gestionnaire.erase_object(sheet, obj);
}
void AppWin2Back::debug_button_clicked() const noexcept { void AppWin2Back::debug_button_clicked() const noexcept {
const json j{ { "character_sheet", sheet } }; spdlog::info("Display objects");
spdlog::info("Character sheet in json: \n{}", j.dump(4, ' ', true)); for (const auto &obj: sheet.get_objects() | views::values) {
} spdlog::info("Object: {}", obj->to_string());
static void convert_to_label(std::array<char, 10> &convert,
const std::string_view &err_msg,
const uint32_t data,
Gtk::Label *const __restrict label) noexcept {
if (const auto [ptr, ec] = std::to_chars(convert.data(), convert.data() + convert.size(), data);
ec != std::errc()) {
spdlog::error("An error occurred while converting {} value: {}",
err_msg,
std::make_error_code(ec).message());
} else {
const Glib::ustring converted{
convert.data(), static_cast<std::string::size_type>(ptr - convert.data())
};
label->set_label(converted);
} }
} }
static void update_in_labels(const character::characteristic::Characteristic &charac,
const std::string_view short_name,
const CaracInterface<Gtk::Label> &labels) noexcept {
std::array<char, 10> convert{};
convert_to_label(convert, std::format("base {}", short_name), charac.get_base(), labels.base);
convert_to_label(convert,
std::format("carac {}", short_name),
charac.get_carac(),
labels.carac);
convert_to_label(convert,
std::format("materiel {}", short_name),
charac.get_materiel(),
labels.mat);
convert_to_label(convert,
std::format("total {}", short_name),
charac.get_total(),
labels.total);
}
void AppWin2Back::update_labels() const noexcept {
update_in_labels(sheet.get_habilete(), "hab", hab_labels);
update_in_labels(sheet.get_endurance(), "endu", endu_labels);
}
bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept { bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept {
return gestionnaire.insert_object(sheet, obj); return gestionnaire.insert_object(sheet, obj);
} }

View file

@ -5,7 +5,6 @@
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <gtkmm/application.h> #include <gtkmm/application.h>
#include <gtkmm/builder.h>
#include <gtkmm/checkbutton.h> #include <gtkmm/checkbutton.h>
#include <billy_objects.hpp> #include <billy_objects.hpp>
@ -16,28 +15,12 @@ namespace learn_gtkmm4 {
} }
namespace Gtk { namespace Gtk {
class Builder;
class Label; class Label;
class Button; class Button;
} }
namespace gui_to_app { namespace gui_to_app {
template<typename T>
struct CaracInterface final {
T *base{ nullptr };
T *carac{ nullptr };
T *mat{ nullptr };
T *total{ nullptr };
CaracInterface() = default;
explicit CaracInterface(const std::array<std::string_view, 4> &list,
const Glib::RefPtr<Gtk::Builder> &builder) :
base(builder->get_widget<T>(list[0].data())),
carac(builder->get_widget<T>(list[1].data())),
mat(builder->get_widget<T>(list[2].data())),
total(builder->get_widget<T>(list[3].data())) {}
};
class AppWin2Back final : public Gtk::Application { class AppWin2Back final : public Gtk::Application {
public: public:
~AppWin2Back() noexcept final = default; ~AppWin2Back() noexcept final = default;
@ -75,9 +58,9 @@ namespace gui_to_app {
void on_quit() noexcept; void on_quit() noexcept;
void debug_button_clicked() const noexcept; bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept;
void update_labels() const noexcept; void debug_button_clicked() const noexcept;
bool insert_obj(const character::billyEnums &obj) noexcept; bool insert_obj(const character::billyEnums &obj) noexcept;
@ -100,9 +83,10 @@ namespace gui_to_app {
selection_button *rock_kit_switch{ nullptr }; selection_button *rock_kit_switch{ nullptr };
selection_button *sack_switch{ nullptr }; selection_button *sack_switch{ nullptr };
CaracInterface<Gtk::Label> hab_labels; Gtk::Label *hab_base{ nullptr };
Gtk::Label *hab_carac{ nullptr };
CaracInterface<Gtk::Label> endu_labels; Gtk::Label *hab_mat{ nullptr };
Gtk::Label *hab_total{ nullptr };
Gtk::Button *debug_button{ nullptr }; Gtk::Button *debug_button{ nullptr };

View file

@ -30,7 +30,6 @@
<object class="GtkGrid"> <object class="GtkGrid">
<child> <child>
<object class="GtkGrid"> <object class="GtkGrid">
<property name="hexpand">True</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="halign">start</property> <property name="halign">start</property>
@ -44,8 +43,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="habilete_label_base"> <object class="GtkLabel" id="habilete_label_base">
<property name="halign">center</property> <property name="halign">end</property>
<property name="hexpand">True</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -64,7 +62,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="habilete_label_carac"> <object class="GtkLabel" id="habilete_label_carac">
<property name="halign">center</property> <property name="halign">end</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>
@ -83,7 +81,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="habilete_label_materiel"> <object class="GtkLabel" id="habilete_label_materiel">
<property name="halign">center</property> <property name="halign">end</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">2</property> <property name="row">2</property>
@ -107,9 +105,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="habilete_label_total"> <object class="GtkLabel" id="habilete_label_total">
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="valign">center</property>
<layout> <layout>
<property name="column">2</property> <property name="column">2</property>
<property name="row">0</property> <property name="row">0</property>
@ -138,11 +133,8 @@
</child> </child>
<child> <child>
<object class="GtkGrid"> <object class="GtkGrid">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child> <child>
<object class="GtkGrid"> <object class="GtkGrid">
<property name="hexpand">True</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="halign">start</property> <property name="halign">start</property>
@ -156,8 +148,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="endurance_label_base"> <object class="GtkLabel" id="endurance_label_base">
<property name="halign">center</property> <property name="halign">end</property>
<property name="hexpand">True</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -176,7 +167,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="endurance_label_carac"> <object class="GtkLabel" id="endurance_label_carac">
<property name="halign">center</property> <property name="halign">end</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>
@ -195,7 +186,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="endurance_label_materiel"> <object class="GtkLabel" id="endurance_label_materiel">
<property name="halign">center</property> <property name="halign">end</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">2</property> <property name="row">2</property>
@ -219,8 +210,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="endurance_label_total"> <object class="GtkLabel" id="endurance_label_total">
<property name="halign">center</property>
<property name="hexpand">True</property>
<layout> <layout>
<property name="column">2</property> <property name="column">2</property>
<property name="row">0</property> <property name="row">0</property>