blob: c2b4afa4c24a025718cb332704be8c5c027c0391 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "turns/app/widgets/turn_order_view.hpp"
#include "turns/app/widgets/participant_row.hpp"
#include "turns/domain/participant.hpp"
#include "turns/lang/messages.hpp"
#include <algorithm>
#include <format>
#include <sigc++/functors/mem_fun.h>
namespace turns::app::widgets
{
namespace
{
auto constexpr static TYPE_NAME = "turn_order_view";
auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/turn_order_view.ui";
} // namespace
turn_order_view::turn_order_view()
: Glib::ObjectBase(TYPE_NAME)
, template_widget<turn_order_view, Gtk::ScrolledWindow>{TEMPLATE}
, m_model{domain::turn_order::create()}
, m_view{get_widget<Gtk::ListBox>("view")}
{
m_view->bind_model(m_model->list_model(), sigc::mem_fun(*this, &turn_order_view::handle_create_row));
m_model->property_active_participant().signal_changed().connect(sigc::mem_fun(*this, &turn_order_view::handle_active_participant_changed));
}
auto turn_order_view::get_model() const noexcept -> Glib::RefPtr<domain::turn_order>
{
return m_model;
}
auto turn_order_view::handle_active_participant_changed() -> void
{
std::ranges::for_each(m_view->get_children(), [](auto c) { c->remove_css_class("active-participant"); });
auto index = m_model->active_participant();
if (index != std::numeric_limits<domain::turn_order::active_participant_type>::max())
{
auto row = m_view->get_row_at_index(index);
row->add_css_class("active-participant");
row->grab_focus();
}
}
auto turn_order_view::handle_create_row(Glib::RefPtr<Glib::Object> const item) -> Gtk::Widget *
{
auto participant = std::dynamic_pointer_cast<domain::participant>(item);
return Gtk::make_managed<widgets::participant_row>(participant);
}
} // namespace turns::app::widgets
|