Compare commits

..

5 commits

Author SHA1 Message Date
93eb59b918
Refactoring 2026-03-16 21:42:47 +01:00
2a975da064
Same with endu 2026-03-16 21:11:01 +01:00
a6b6e0d5bf
Habileté labels in struct 2026-03-16 21:10:46 +01:00
d909c627e0
Better look 2026-03-16 16:23:43 +01:00
53a70aefa5
Updating hab labels 2026-03-16 16:23:26 +01:00
3 changed files with 103 additions and 23 deletions

View file

@ -50,6 +50,8 @@ namespace gui_to_app {
if (!app.insert_obj(obj)) {
on_stack = true;
switch_->set_active(false);
} else {
app.update_labels();
}
} else {
if (!app.erase_obj(obj)) {
@ -59,6 +61,8 @@ namespace gui_to_app {
"Erasing object {} was not successful",
character::BillyObjects::billy_object_to_string(obj).data()
);
} else {
app.update_labels();
}
}
}
@ -165,10 +169,24 @@ namespace gui_to_app {
return;
}
debug_button = app_builder->get_widget<Gtk::Button>("debug_button");
hab_base = app_builder->get_widget<Gtk::Label>("habilete_label_base");
hab_carac = app_builder->get_widget<Gtk::Label>("habilete_label_carac");
hab_mat = app_builder->get_widget<Gtk::Label>("habilete_label_materiel");
hab_total = app_builder->get_widget<Gtk::Label>("habilete_label_total");
hab_labels = CaracInterface<Gtk::Label>{
{
"habilete_label_base",
"habilete_label_carac",
"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);
}
@ -182,17 +200,52 @@ namespace gui_to_app {
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 {
const json j{ { "character_sheet", sheet } };
spdlog::info("Character sheet in json: \n{}", j.dump(4, ' ', true));
}
void AppWin2Back::debug_button_clicked() const noexcept {
spdlog::info("Display objects");
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 {
return gestionnaire.insert_object(sheet, obj);
}

View file

@ -5,6 +5,7 @@
#include <glibmm/refptr.h>
#include <gtkmm/application.h>
#include <gtkmm/builder.h>
#include <gtkmm/checkbutton.h>
#include <billy_objects.hpp>
@ -15,12 +16,28 @@ namespace learn_gtkmm4 {
}
namespace Gtk {
class Builder;
class Label;
class Button;
}
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 {
public:
~AppWin2Back() noexcept final = default;
@ -58,10 +75,10 @@ namespace gui_to_app {
void on_quit() noexcept;
bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept;
void debug_button_clicked() const noexcept;
void update_labels() const noexcept;
bool insert_obj(const character::billyEnums &obj) noexcept;
bool erase_obj(const character::billyEnums &obj) noexcept;
@ -83,10 +100,9 @@ namespace gui_to_app {
selection_button *rock_kit_switch{ nullptr };
selection_button *sack_switch{ nullptr };
Gtk::Label *hab_base{ nullptr };
Gtk::Label *hab_carac{ nullptr };
Gtk::Label *hab_mat{ nullptr };
Gtk::Label *hab_total{ nullptr };
CaracInterface<Gtk::Label> hab_labels;
CaracInterface<Gtk::Label> endu_labels;
Gtk::Button *debug_button{ nullptr };

View file

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