diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-06-09 08:53:35 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-06-09 08:54:11 +0200 |
| commit | 85b1b7b36b1aa8c7acadef5d74708ce4a3a79ef3 (patch) | |
| tree | c11ddf4bf6673a7307eef1856f8b069881a54762 /gui/src | |
| parent | b6b4399b20648de28def5411d90c4a3536da5b01 (diff) | |
| download | turns-85b1b7b36b1aa8c7acadef5d74708ce4a3a79ef3.tar.xz turns-85b1b7b36b1aa8c7acadef5d74708ce4a3a79ef3.zip | |
gui: make ParticipantRow default constructible
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/init.cpp | 2 | ||||
| -rw-r--r-- | gui/src/participant_row.cpp | 86 |
2 files changed, 42 insertions, 46 deletions
diff --git a/gui/src/init.cpp b/gui/src/init.cpp index 378065c..9192d37 100644 --- a/gui/src/init.cpp +++ b/gui/src/init.cpp @@ -15,7 +15,7 @@ auto Turns::gui::init() -> void { - g_type_ensure(ParticipantRow{nullptr}.get_type()); + g_type_ensure(ParticipantRow{}.get_type()); g_type_ensure(ParticipantEditor{nullptr}.get_type()); g_type_ensure(Preferences{}.get_type()); g_type_ensure(Tracker{{}, {}}.get_type()); diff --git a/gui/src/participant_row.cpp b/gui/src/participant_row.cpp index e01da67..ba39a2f 100644 --- a/gui/src/participant_row.cpp +++ b/gui/src/participant_row.cpp @@ -52,9 +52,14 @@ namespace Turns::gui return ""; } } + + auto format_priority(float priority) -> Glib::ustring + { + return std::vformat(_(message::priority_number), std::make_format_args(priority)); + } } // namespace - ParticipantRow::ParticipantRow(Glib::RefPtr<Participant> participant) + ParticipantRow::ParticipantRow() : Glib::ObjectBase(TYPE_NAME) , template_widget{TEMPLATE} , m_delete{get_widget<Gtk::Button>("delete")} @@ -82,53 +87,44 @@ namespace Turns::gui Glib::Binding::Flags::SYNC_CREATE, [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); - // clang-format off - Glib::Binding::bind_property(delete_enabled(), - m_delete->property_sensitive(), - Glib::Binding::Flags::SYNC_CREATE); - Glib::Binding::bind_property(edit_enabled(), - m_edit->property_sensitive(), - Glib::Binding::Flags::SYNC_CREATE); - // clang-format on + Glib::Binding::bind_property(delete_enabled(), m_delete->property_sensitive(), Glib::Binding::Flags::SYNC_CREATE); + Glib::Binding::bind_property(edit_enabled(), m_edit->property_sensitive(), Glib::Binding::Flags::SYNC_CREATE); + } - if (participant) - { - Glib::Binding::bind_property(participant->property_name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE); - - Glib::Binding::bind_property(participant->property_priority(), - m_subtitle->property_label(), - Glib::Binding::Flags::SYNC_CREATE, - [](auto n) { return std::vformat(_(message::priority_number), std::make_format_args(n)); }); - - Glib::Binding::bind_property(participant->property_disposition(), - m_toggle_defeated->property_css_classes(), - Glib::Binding::Flags::SYNC_CREATE, - [this](auto value) { - auto classes = m_toggle_defeated->get_css_classes(); - auto removed = std::ranges::remove_if(classes, [](auto cls) { - return (cls == "disposition-friendly") | (cls == "disposition-hostile") || (cls == "disposition-secret"); - }); - classes.erase(removed.begin(), removed.end()); - classes.push_back(css_class_for(value)); - return classes; - }); + ParticipantRow::ParticipantRow(Glib::RefPtr<Participant> participant) + : ParticipantRow{} + { + Glib::Binding::bind_property(participant->property_name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE); + Glib::Binding::bind_property(participant->property_priority(), + m_subtitle->property_label(), + Glib::Binding::Flags::SYNC_CREATE, + &format_priority); - Glib::Binding::bind_property(participant->property_active(), - property_css_classes(), - Glib::Binding::Flags::SYNC_CREATE, - [this](auto value) { - auto classes = get_css_classes(); - if (!value) - { - std::erase(classes, "active-participant"); - } - else - { - classes.push_back("active-participant"); - } - return classes; + Glib::Binding::bind_property(participant->property_disposition(), + m_toggle_defeated->property_css_classes(), + Glib::Binding::Flags::SYNC_CREATE, + [this](auto value) { + auto classes = m_toggle_defeated->get_css_classes(); + auto removed = std::ranges::remove_if(classes, [](auto cls) { + return (cls == "disposition-friendly") | (cls == "disposition-hostile") || (cls == "disposition-secret"); }); - } + classes.erase(removed.begin(), removed.end()); + classes.push_back(css_class_for(value)); + return classes; + }); + + Glib::Binding::bind_property(participant->property_active(), property_css_classes(), Glib::Binding::Flags::SYNC_CREATE, [this](auto value) { + auto classes = get_css_classes(); + if (!value) + { + std::erase(classes, "active-participant"); + } + else + { + classes.push_back("active-participant"); + } + return classes; + }); } auto ParticipantRow::delete_enabled() -> Glib::PropertyProxy<bool> |
