aboutsummaryrefslogtreecommitdiff
path: root/app/src/widgets/turn_order_view.cpp
blob: 9d49ad8f2704bf9cdd77775188dca16f83afd543 (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
55
56
57
58
59
60
61
62
63
64
65
66
#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_n_items{m_model.get(), "n_items"}
  {
    m_view->bind_model(m_model, sigc::mem_fun(*this, &turn_order_view::handle_create_row));
  }

  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_n_items() const noexcept -> unsigned int
  {
    return m_n_items;
  }

  auto turn_order_view::property_n_items() const -> Glib::PropertyProxy_ReadOnly<unsigned int>
  {
    return m_n_items;
  }

  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