diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-15 16:00:29 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-15 16:00:29 +0200 |
| commit | a23cda29f0acef40d883c37209389c956c14e83b (patch) | |
| tree | 8d9cb59da154da5cbe75cedbaf6b52ebc8d2eb54 /app/src/widgets | |
| parent | bcea0775a7a07738b3eec1b00cef618de84f3e41 (diff) | |
| download | turns-a23cda29f0acef40d883c37209389c956c14e83b.tar.xz turns-a23cda29f0acef40d883c37209389c956c14e83b.zip | |
turns: perform widespread code cleanup actions
Diffstat (limited to 'app/src/widgets')
| -rw-r--r-- | app/src/widgets/participant_list_row.cpp | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/app/src/widgets/participant_list_row.cpp b/app/src/widgets/participant_list_row.cpp index e38b532..9be3c57 100644 --- a/app/src/widgets/participant_list_row.cpp +++ b/app/src/widgets/participant_list_row.cpp @@ -2,6 +2,7 @@ #include "turns/lang/messages.hpp" +#include <format> #include <print> #include <glibmm/i18n.h> @@ -16,41 +17,60 @@ namespace turns::app::widgets auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/participant_list_row.ui"; } // namespace - participant_list_row::participant_list_row() + participant_list_row::participant_list_row(Glib::RefPtr<domain::participant> participant) : Glib::ObjectBase(TYPE_NAME) , template_widget<participant_list_row, Gtk::ListBoxRow>{TEMPLATE} + , m_delete{get_widget<Gtk::Button>("delete")} + , m_edit{get_widget<Gtk::Button>("edit")} + , m_subtitle{get_widget<Gtk::Label>("subtitle")} + , m_title{get_widget<Gtk::Label>("title")} + , m_toggle_defeated{get_widget<Gtk::ToggleButton>("toggle_defeated")} + , m_subtitle_visibility{} { - m_delete = get_widget<Gtk::Button>("delete"); - m_edit = get_widget<Gtk::Button>("edit"); - m_subtitle = get_widget<Gtk::Label>("subtitle"); - m_title = get_widget<Gtk::Label>("title"); - m_toggle_defeated = get_widget<Gtk::ToggleButton>("toggle_defeated"); - - m_delete->signal_clicked().connect([this] { activate_action("win.delete", Glib::Variant<int>::create(get_index())); }); - m_edit->signal_clicked().connect([this] { activate_action("win.edit", Glib::Variant<int>::create(get_index())); }); - m_toggle_defeated->signal_toggled().connect(sigc::mem_fun(*this, &participant_list_row::handle_toggle_defeated)); + m_delete->signal_clicked().connect(sigc::mem_fun(*this, &participant_list_row::handle_delete)); + m_edit->signal_clicked().connect(sigc::mem_fun(*this, &participant_list_row::handle_edit)); + + m_subtitle_visibility = Glib::Binding::bind_property(m_subtitle->property_label(), + m_subtitle->property_visible(), + Glib::Binding::Flags::DEFAULT, + sigc::mem_fun(&Glib::ustring::size)); + m_title_visibility = Glib::Binding::bind_property(m_title->property_label(), + m_title->property_visible(), + Glib::Binding::Flags::INVERT_BOOLEAN, + sigc::mem_fun(&Glib::ustring::size)); + m_toggle_defeated_icon = Glib::Binding::bind_property(m_toggle_defeated->property_active(), + m_toggle_defeated->property_icon_name(), + Glib::Binding::Flags::SYNC_CREATE, + [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); + + if (participant) + { + set_title(participant->get_name()); + auto priority = participant->get_priority(); + set_subtitle(std::vformat(_(lang::priority_number), std::make_format_args(priority))); + } } auto participant_list_row::set_subtitle(Glib::ustring const & value) -> void { - m_subtitle->set_text(value); - m_subtitle->set_visible(!value.empty()); + m_subtitle->property_label() = value; } auto participant_list_row::set_title(Glib::ustring const & value) -> void { - m_title->set_text(value); - m_title->set_visible(!value.empty()); + m_title->property_label() = value; } - auto participant_list_row::handle_toggle_defeated() -> void + auto participant_list_row::handle_delete() -> void { - if (m_toggle_defeated->get_active()) - { - m_toggle_defeated->set_icon_name("face-sick-symbolic"); - return; - } - m_toggle_defeated->set_icon_name("face-smile-symbolic"); + auto index = Glib::Variant<int>::create(get_index()); + activate_action("win.delete", index); + } + + auto participant_list_row::handle_edit() -> void + { + auto index = Glib::Variant<int>::create(get_index()); + activate_action("win.edit", index); } } // namespace turns::app::widgets
\ No newline at end of file |
