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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#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 <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_is_empty{*this, "is_empty", true}
{
m_view->bind_model(m_model, sigc::mem_fun(*this, &turn_order_view::handle_create_row));
// clang-format off
Glib::Binding::bind_property(m_model->property_n_items(),
m_is_empty.get_proxy(),
Glib::Binding::Flags::DEFAULT,
[](auto n) { return n == 0; });
// clang-format on
}
auto turn_order_view::append(Glib::ustring name, float priority, domain::disposition disposition) -> void
{
auto participant = domain::participant::create(name, priority, disposition);
m_model->append(participant);
}
auto turn_order_view::clear() -> void
{
m_model->remove_all();
}
auto turn_order_view::get(std::size_t index) -> Glib::RefPtr<domain::participant>
{
return m_model->get_item(index);
}
auto turn_order_view::remove(std::size_t index) -> void
{
m_model->remove(index);
}
auto turn_order_view::get_is_empty() const noexcept -> bool
{
return m_is_empty;
}
auto turn_order_view::property_is_empty() const -> Glib::PropertyProxy_ReadOnly<bool>
{
return m_is_empty.get_proxy();
}
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
|