Compare commits
No commits in common. "93eb59b9182b22a3f3aaf93964645776153f8141" and "a54d1f7e984b52d437a4123ac267a31c121242e7" have entirely different histories.
93eb59b918
...
a54d1f7e98
3 changed files with 23 additions and 103 deletions
|
|
@ -50,8 +50,6 @@ 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)) {
|
||||
|
|
@ -61,8 +59,6 @@ namespace gui_to_app {
|
|||
"Erasing object {} was not successful",
|
||||
character::BillyObjects::billy_object_to_string(obj).data()
|
||||
);
|
||||
} else {
|
||||
app.update_labels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,24 +165,10 @@ namespace gui_to_app {
|
|||
return;
|
||||
}
|
||||
debug_button = app_builder->get_widget<Gtk::Button>("debug_button");
|
||||
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
|
||||
};
|
||||
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");
|
||||
|
||||
debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false);
|
||||
}
|
||||
|
|
@ -200,52 +182,17 @@ 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));
|
||||
}
|
||||
|
||||
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);
|
||||
spdlog::info("Display objects");
|
||||
for (const auto &obj: sheet.get_objects() | views::values) {
|
||||
spdlog::info("Object: {}", obj->to_string());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include <glibmm/refptr.h>
|
||||
#include <gtkmm/application.h>
|
||||
#include <gtkmm/builder.h>
|
||||
#include <gtkmm/checkbutton.h>
|
||||
|
||||
#include <billy_objects.hpp>
|
||||
|
|
@ -16,28 +15,12 @@ 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;
|
||||
|
|
@ -75,9 +58,9 @@ namespace gui_to_app {
|
|||
|
||||
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;
|
||||
|
||||
|
|
@ -100,9 +83,10 @@ namespace gui_to_app {
|
|||
selection_button *rock_kit_switch{ nullptr };
|
||||
selection_button *sack_switch{ nullptr };
|
||||
|
||||
CaracInterface<Gtk::Label> hab_labels;
|
||||
|
||||
CaracInterface<Gtk::Label> endu_labels;
|
||||
Gtk::Label *hab_base{ nullptr };
|
||||
Gtk::Label *hab_carac{ nullptr };
|
||||
Gtk::Label *hab_mat{ nullptr };
|
||||
Gtk::Label *hab_total{ nullptr };
|
||||
|
||||
Gtk::Button *debug_button{ nullptr };
|
||||
|
||||
|
|
|
|||
23
window_ui.ui
23
window_ui.ui
|
|
@ -30,7 +30,6 @@
|
|||
<object class="GtkGrid">
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="hexpand">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="halign">start</property>
|
||||
|
|
@ -44,8 +43,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="habilete_label_base">
|
||||
<property name="halign">center</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">0</property>
|
||||
|
|
@ -64,7 +62,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="habilete_label_carac">
|
||||
<property name="halign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">1</property>
|
||||
|
|
@ -83,7 +81,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="habilete_label_materiel">
|
||||
<property name="halign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">2</property>
|
||||
|
|
@ -107,9 +105,6 @@
|
|||
</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>
|
||||
|
|
@ -138,11 +133,8 @@
|
|||
</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>
|
||||
|
|
@ -156,8 +148,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="endurance_label_base">
|
||||
<property name="halign">center</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">0</property>
|
||||
|
|
@ -176,7 +167,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="endurance_label_carac">
|
||||
<property name="halign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">1</property>
|
||||
|
|
@ -195,7 +186,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="endurance_label_materiel">
|
||||
<property name="halign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">2</property>
|
||||
|
|
@ -219,8 +210,6 @@
|
|||
</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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue